Afficher un message
Vieux 01/07/2008, 05h16   #1
hill.liu@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut class instantiation question

Hi,

I stuck into this problem that I can't figure it out.
Here is the class definition:

class ctest {
public:
ctest(void) { cout << "ctest default constor" << endl; };
ctest(ctest& c) { cout <<"ctest copy constr" << endl; };
ctest(int a) { cout <<"ctest int constor" <<endl; };

ctest& operator= (ctest& a) { cout << "ctest copy assignment" <<
endl; return *this; };
operator int() { cout << "call operator int()" <<endl; return 20; }
};

int main(void)
{
ctest cc = ctest();
}

And it outputs as following:
ctest default constor
call operator int()
ctest int constor

I wonder why it will invoke "operator int()" and call "constructor
with int as argument".

Thanks
Brad
  Réponse avec citation
 
Page generated in 0,05177 seconds with 9 queries