Are you allowed to initialize the private members in the class directly like i did below? ............. because i thought the nothing is created in memory until you create the object..... so can somebody explain this please?
1 2 3 4 5 6
class Circle
{
private:
double radius;
double pi = 3.14;
}
> because i thought the nothing is created in memory until you create the object
You are right. The = 3.14 is an initializer. When an object is created, constructor(s) can use the information to initialize the member variable (if it has not been explicitly initialized by the code in the constructor).