Is the default constructor always called C ++, as stated in the C ++ Primer?

I am new to C ++. Ignore this stupid question:

In C ++, primer 4th edition (Stanley Lippmann) on page 52 has a sentence that says:

The default constructor is used regardless of where the variable is defined.

Can someone explain a little more? These statements seem to be missing something.

+5
source share
4 answers

From the book itself:

, , , . , , . , " "; , . , .

( ).

, , ( , ).

, , , , , ( , , , , ..).

+4

Object:

class Object
{
public:
    int x;

    Object() { x = 5; }
};

, :

void foo()
{
    Object obj;
    // obj.x == 5
}

. , :

class AnotherObject
{
public:
    Object obj;
};

void bar()
{
    AnotherObject another;
    // another.obj.x == 5
}
+3

, ?

, , , , , - :

myclass X;

... X ctor , , ( ), - (, for).

+2

$12,1

(12.1), (12.8) (12.4) -. - , , 12.1. , , 12.1, 12.4 12.8. -. -. [: , -.

0

All Articles