testref.cpp: In function ‘int main()’:testref.cpp:10: error: ‘A::A(const A&)’ is privatetestref.cpp:20: error: within this context
这是代码
#include <cstdio>class A {public: A() { i=0; printf("A ctor\n"); } ~A() { printf("A dtor\n"); }private: A(const A& other) { i=other.i; printf("A copY CTOR\n"); } A& operator=(const A& other) { i=other.i; printf("A copY operator\n"); return *this; }private: int i;};voID f(const A &aref) { printf("dummy\n");} int main() { f(A()); return 0; }
在这种情况下不需要这个拷贝构造函数,因为f得到一个引用(我公开它是为了看它是否被调用而它没有).
另外,我已经使f按值获取对象,并且仍然既没有复制构造函数也没有调用operator =.我怀疑这可能与优化有关.
有什么建议?
谢谢.
test.cpp:20:7: warning: C++98 requires an accessible copy constructor for class 'A' when binding a reference to a temporary; was private
编辑:我没有附近的标准副本给你完整的推理.希望其他人(或谷歌)可以.
总结以上是内存溢出为你收集整理的c – gcc编译错误(关于复制c’tors)看起来很奇怪(至少对我而言)全部内容,希望文章能够帮你解决c – gcc编译错误(关于复制c’tors)看起来很奇怪(至少对我而言)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)