C ++ Structures and Constructors

A quick question about C ++ structures, to which I could not find the answer:

I read that the only difference between structures and classes is the visibility of members. So, does the compiler provide the structure with a default constructor? (and by default copyconstructor, destructor and assignment operator?) And can you define all of the above yourself?

Thanks, Istvan

+5
source share
4 answers

Yes it is, and yes you can.

+11
source

Yes to all your questions. The same is true for classes.

+1
source

, - .

. , :

struct S1 { int m1; };
struct S2: S1 { int m2; };

S2, m2 m1 . S2* , S1*.

+1

++ class a struct , , struct - . , , , . .

.

struct TestStruct {
        int id;
        TestStruct() : id(42)
        {
        }
};

question.

0

All Articles