Here is an example of minimal code that illustrates the problem:
#include <iostream> class Thing { // Non-copyable Thing(const Thing&); Thing& operator=(const Thing&); int n_; public: Thing(int n) : n_(n) {} int getValue() const { return n_;} }; void show(const Thing& t) { std::cout << t.getValue() << std::endl; } int main() { show(3); }
This gives the same error:
int main() { show( Thing(3) ); }
The IBM XL C / C ++ 8.0 compiler on AIX displays the following warnings:
"testWarning.cpp", line 24.9: 1540-0306 (W) The "private" copy constructor "Thing(const Thing &)" cannot be accessed. "testWarning.cpp", line 24.9: 1540-0308 (I) The semantics specify that a temporary object must be constructed. "testWarning.cpp", line 24.9: 1540-0309 (I) The temporary is not constructed, but the copy constructor must be accessible.
I also tried g ++ 4.1.2 with "-Wall" and "-pedantic" and did not get any diagnostics. Why is access to the copy constructor needed here? How can I eliminate this warning, in addition to copying an object (which is beyond my control) or making an explicit copy for transmission (when a real object is expensive to copy)?
c ++ compiler-warnings aix ibm
Fred Larson Oct 23 '09 at 20:15 2009-10-23 20:15
source share