we have a class like this:
class int2
{
public:
int2(int a)
{
}
};
are these two lines:int2 s(10);
int2 s = 10;completely equivalent in any C++ compiler & any compiler options?
Edited by irancplusplus, 06 February 2012 - 07:04 AM.
class int2
{
public:
int2(int a)
{
}
};
are these two lines:int2 s(10);
int2 s = 10;completely equivalent in any C++ compiler & any compiler options?
Edited by irancplusplus, 06 February 2012 - 07:04 AM.
|
|
|
class int2 {
int a;
public :
int2(int b) : a(b)
{
}
};
class int2
{
};
If you write above code, compilers (as far as I know any compiler) will generate 3 things for you -- i) default constructor, ii) copy constructor and iii) assignment operator (overloading). So the generated code will be something like following...
class int2
{
public:
int2(){} // This is the reason you are able to write 'int2 i2;'
int2(const int2 &other) {} // This is the reason you are able to write 'int2 i1; int2 i2(i1); int2 i2=i1; '
int2 operator=(const int2& other){} // This is the reason you are able to write 'int2 i1; int2 i2; i2 = i1; '
};
0 members, 1 guests, 0 anonymous users