I
Ioannis Vranos
For the code
#include <iostream>
class Blah
{
int i;
public:
Blah(const Blah &obj)
{
std::cout<<"Copy Constructor called!\n";
i=obj.i;
}
Blah()
{
std::cout<<"Default Constructor called!\n"; i=0;
}
};
int main()
{
Blah poo1(Blah());
Blah poo2=Blah();
}
I only get
C:\c>temp
Default Constructor called!
C:\c>
which is produced for the second object while nothing is produced for
the first.
Why no message is produced for the first, and why only a default
constructor message is produced for the second?
I expected:
C:\c>temp
Default Constructor called!
Copy Constructor called!
Default Constructor called!
Copy Constructor called!
C:\c>
#include <iostream>
class Blah
{
int i;
public:
Blah(const Blah &obj)
{
std::cout<<"Copy Constructor called!\n";
i=obj.i;
}
Blah()
{
std::cout<<"Default Constructor called!\n"; i=0;
}
};
int main()
{
Blah poo1(Blah());
Blah poo2=Blah();
}
I only get
C:\c>temp
Default Constructor called!
C:\c>
which is produced for the second object while nothing is produced for
the first.
Why no message is produced for the first, and why only a default
constructor message is produced for the second?
I expected:
C:\c>temp
Default Constructor called!
Copy Constructor called!
Default Constructor called!
Copy Constructor called!
C:\c>