
Untitled
By: a guest on
May 2nd, 2012 | syntax:
None | size: 0.75 KB | hits: 15 | expires: Never
A gcc compilation error (concerning copy c'tors) which seems odd (at least to me)
testref.cpp: In function ‘int main()’:
testref.cpp:10: error: ‘A::A(const A&)’ is private
testref.cpp:20: error: within this context
#include <cstdio>
class A {
public:
A() { i=0; printf("A ctorn"); }
~A() { printf("A dtorn"); }
private:
A(const A& other) { i=other.i; printf("A COPY CTORn"); }
A& operator=(const A& other) { i=other.i; printf("A COPY operatorn"); return *this; }
private:
int i;
};
void f(const A &aref) {
printf("dummyn");
}
int main() {
f(A());
return 0;
}
test.cpp:20:7: warning: C++98 requires an accessible copy constructor for class
'A' when binding a reference to a temporary; was private