In C programming if i will declare a structure with private fields and some public methods, will it behave as a class?
Asked
Active
Viewed 37 times
1 Answers
3
A class
's members are private
by default, and a struct
's are public
:
class A {
int x; // this is private to A
};
struct B {
int y; // this is public
};
Also when it comes to inheritance, a class
will inherit private
ly by default and a struct
will inherit public
ally:
class C : B { }; // private inheritance
struct D : B { }; // public inheritance
That's it.

Barry
- 286,269
- 29
- 621
- 977