Feb 5, 2018

[C++] injected class name

class X { };
X x1;
class X::X x2; // class X::X is equal to X
class X::X::X x3; // ...and so on...

# quote from S.O
The injected class name means that X is declared as a member of X, so that name lookup inside X always finds the current class, not another X that might be declared at the same enclosing scope, e.g.

void X() { }
class X {
public:
  static X create() { return X(); }
};

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.