What does B(int b=0):b(b){}
mean in the following portion of code?
class B
{
int b;
public:
B(int b=0):b(b){}
};
What does B(int b=0):b(b){}
mean in the following portion of code?
class B
{
int b;
public:
B(int b=0):b(b){}
};
It's an empty constructor definition.
class B
{
int b;
public:
B (int b = 0) //Default initialize b to 0
: b(b) //Initialize member b to parameter b
{ } //Empty constructor definition
};
You could write instead of the constructor
B (int b = 0)
: b(b)
{ }
also this:
B (int b = 0)
{
this->b = b;
}