Constructor or Assignment Operator

Posted by ju on Stack Overflow See other posts from Stack Overflow or by ju
Published on 2010-05-17T09:10:15Z Indexed on 2010/05/17 9:20 UTC
Read the original article Hit count: 298

Can you help me is there definition in C++ standard that describes which one will be called constructor or assignment operator in this case:

#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& operatorint rhs)
 {
  m_nTest = rhs;
  cout << "Assignment" << endl;
  return *this;
 }

protected:
 int m_nTest;
};

int _tmain(int argc, _TCHAR* argv[])
{
 CTest b = 5;

 return 0;
}

Or is it just a matter of compiler optimization?

© Stack Overflow or respective owner

Related posts about c++

Related posts about copy-constructor