这是一个说明问题的最小代码示例:
#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);
}
Run Code Online (Sandbox Code Playgroud)
这会产生相同的错误:
int main()
{
show( Thing(3) );
}
Run Code Online (Sandbox Code Playgroud)
AIX下的IBM XL C/C++ 8.0编译器会发出以下警告:
"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 …Run Code Online (Sandbox Code Playgroud)