In the below example, I initialize obj
with itself.
#include <iostream>
class base {
public:
base()
{
std::cout << "base" << std::endl;
}
base(const base& obj)
{
std::cout << "copy base" << std::endl;
}
};
int main ()
{
base obj = obj;
}
This program prints "copy base".
Why default constructor isn't called?
Why there is no error?
Why is it allowed?