你能帮我在 C++ 标准中有定义,描述在这种情况下哪个将被称为构造函数或赋值运算符:
#include <iostream>
using namespace std;
class CTest
{
public:
CTest() : m_nTest(0)
{
cout << "Default constructor" << endl;
}
CTest(int a) : m_nTest(a)
{
cout << "Int constructor" << endl;
}
CTest(const CTest& obj)
{
m_nTest = obj.m_nTest;
cout << "Copy constructor" << endl;
}
CTest& operator=(int rhs)
{
m_nTest = rhs;
cout << "Assignment" << endl;
return *this;
}
protected:
int m_nTest;
};
int _tmain(int argc, _TCHAR* argv[])
{
CTest b = 5;
return 0;
}
还是只是编译器优化的问题?