thed0ctor
thed0ctor

Reputation: 1406

How do the ways to declare visibility/access in C++ differ?

This may be a silly question, but is there any difference in terms of efficiency, optimization etc in how you can declare access in classes in C++?

As a specific example is it more efficient, less efficient, or neither to declare visibility for each attribute/method in a class vs declaring visibility (i.e. private/public/protected) "blocks" in classes.

For example, is the following code:

class Foo{
  private:
    int member1;
    string member2;
    ...
    Thing memberN;

  public:
    int member2;
    Thing member3;
    ...
    string memberM;
}

more efficient than:

class Foo{
  private:
    int member1;

  private:
    string member2;

  private:
    ...

  private:
    Thing memberN;

  public:
    int member2;

  public:
    Thing member3;

  public:
    ...

  public:
    string memberM;


}

Upvotes: 0

Views: 83

Answers (1)

SomeWittyUsername
SomeWittyUsername

Reputation: 18368

It's the same. Access modifiers are for compiler usage and result in the same output binary code.

Upvotes: 2

Related Questions