Can there be two public section in a class? If yes then why ? And in which circumstances we do so?

前端 未结 6 498
北恋
北恋 2020-12-25 15:43

There is something bugging me about classes. For example

class A
{
public:
  A()
  {
  .....
  .....
  }

  void cleanup()
  {
  ....
  ....
  ....
  }

publ         


        
6条回答
  •  -上瘾入骨i
    2020-12-25 16:02

    The class is correct, public is just a access qualifier and will apply till the next qualifier is seen or the end of class declaration. There is no limit to how many of these access qualifiers(public, private, protected) you can have in a class. As to why this is useful, it helps writing class declarations the way you want. For example I might want all the member functions (public,protected or private) declared before the (say) private data members.

提交回复
热议问题