+ 2
Can class in c++ be public private and protected??
3 odpowiedzi
+ 4
No it cant be as per my knowledge
+ 4
Yes they can if they are inside another class..
For example iterator of std::vector is a public class inside the vector class from the C++ Standard Template Library.
If you need you can define a private class inside a class, obviously it could become a complicated system.
+ 1
Do you mean if a class can be public private and protected all at the same time, then no it isn't possible, but if you are asking if classes can have access specifiers in c++ then yes it does.
class A {
private:
// Private members
public:
// Public members
protected:
// Protected members
};
In inheritance an entire class can have access specifiers
For example
Class A: public B {
// Same for other specifiers
}