119k views
5 votes
To guarantee that the member variables of a class are initialized, you use ____.

User Rifa
by
7.8k points

1 Answer

3 votes
a constructor, member initialization lists and also the default member initializer. Here you see all three (in reality you choose one construct per variable).

class A
{
public:
int x = 0;

A() : x(1)
{
x = 2;
}
};
User HannahS
by
9.2k points

No related questions found