Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
127 views
in Technique[技术] by (71.8m points)

c++ - calling the default constructor

class base {
    int i;
public:
    base()
    {
        i = 10;
        cout << "in the constructor" << endl;
    }
};

int main()
{
    base a;// here is the point of doubt
    getch();
}

What is the difference between base a and base a()?

in the first case the constructor gets called but not in the second case!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The second one is declaring a function a() that returns a base object. :-)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...