By justin

2012-08-27 02:03:21 8 Comments

I tested on two compilers, and was surprised to see both support the following definition without complaint:

class A {

A::A::A() {}

Note that this also succeeds for methods, although it is flagged when the declaration is over-qualified.


  • Is this a valid C++ program?
  • If so, what purpose does it serve - or is it merely a byproduct?

Updated Detail:

In case the original question was not clear or too short: I'm curious why redundant qualifications are permitted on the definition (emphasis also added above).

Clang an Apple's GCC 4.2 + LLVM were the compilers


@Jerry Coffin 2012-08-27 02:07:53

Yes, it's allowed (§9/2):

The class-name is also inserted into the scope of the class itself; this is known as the injected-class-name. For purposes of access checking, the injected-class-name is treated as if it were a public member name.

For information about the reasoning that lead to class name inject, you might want to read N0444.

@justin 2012-08-27 03:55:02

thanks (+1) -- i have revised the question to emphasize that the definition was the part that was really curious to me (and i realize that may not change your answer).

Related Questions

Sponsored Content

14 Answered Questions

[SOLVED] Why does C++ compilation take so long?

0 Answered Questions

4 Answered Questions

[SOLVED] Embed C++ compiler in application

2 Answered Questions

[SOLVED] Inconsistent use of const qualifier between declaration and definition

  • 2013-12-18 13:03:46
  • detunized
  • 815 View
  • 15 Score
  • 2 Answer
  • Tags:   c++ gcc clang

31 Answered Questions

[SOLVED] Why is this program erroneously rejected by three C++ compilers?

1 Answered Questions

[SOLVED] Why does this let me get a non-const pointer to a field of a const object?

  • 2013-02-12 06:00:00
  • zneak
  • 82 View
  • 0 Score
  • 1 Answer
  • Tags:   c++ const

2 Answered Questions

[SOLVED] Why are redundant class name qualifiers allowed?

6 Answered Questions

3 Answered Questions

[SOLVED] C++'s "inline" - how strong a hint is it for GCC and Clang/LLVM?

Sponsored Content