Link to home
Start Free TrialLog in
Avatar of Monica2003
Monica2003

asked on

Default private access in C++

Hi,

I know that the default access in C++ is private.  But why is the default constructor (compiler's constructor if we don't provide one) public?

Example:

class Dog
{
};

void main()
{
Dog fido;
}

If the default access is private, then why am I still able to instantiate an object of the Dog class?  Thanks.
Avatar of ghimireniraj
ghimireniraj

A default constructor is implicitly declared if you don't declare any
constructor of your own.  An implicitly declared default constructor
is public and inline.

That's how C++ comiler generates obj code.

--Niraj
ASKER CERTIFIED SOLUTION
Avatar of Mysidia
Mysidia
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial