0
#include <iostream>

using namespace std;

class Base{
public:
    Base()
    {
        cout<<"Base()"<<endl;
    }

    Base(const Base& b) 
    {
        cout<<"Base(Base&)"<<endl;
    }

    virtual ~Base()
    {
        cout<<"~Base()"<<endl;
    }
};

int main()
{
    Base b = Base();
    return 0;
}

platform: win7/ CodeBlock/ mingw output result on my screen:

Base()
~Base()

why Base(Base&) was not called?

My Question:
In main(), Base b = Base(); , I think Base() will call Base() Constructor and then a anonymous object was built, after that, "Base b = anonymous object" will call Base(const Base& b), but the output result tell me that the copy-constructor was not called. Can you tell me why?

ellischan
  • 3
  • 2

0 Answers0