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 36 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 privately by default and a struct will inherit publically:
class C : B { }; // private inheritance
struct D : B { }; // public inheritance
That's it.
Barry
- 267,863
- 28
- 545
- 906