#include "stdafx.h"
class Base
{
public:
Base(){}
virtual ~Base(){}
private:
Base(const Base &other) ; // Only declaration! No definition.
Base &operator=(const Base &other);
} ;
int _tmain(int argc, _TCHAR* argv[])
{
const Base b ; // ok
const Base *pb = &Base() ; // ok
const Base &qb = Base() ; // Illegal, why?
return 0;
}
,然后看下面的代码:拷贝赋值为未实现的拷贝构造函数
#include "stdafx.h"
class Base
{
public:
Base(){}
virtual ~Base(){}
public:
Base(const Base &other) ; // Only declaration! No definition.
Base &operator=(const Base &other);
} ;
int _tmain(int argc, _TCHAR* argv[])
{
const Base b ; // ok
const Base *pb = &Base() ; // ok
const Base &qb = Base() ; // It's ok! why?
return 0;
}
你应该添加更多的文字来解释你在找什么。 – Sean
注意'const Base * pb =&Base()'是* not * ok,并且应该从编译器产生一个警告 – stijn
这个'const Base * pb =&Base();'肯定不是* OK。这是一个微软的扩展。 – ybungalobill