7

In Thinking in C++ Volume 1, chapter 16: Introduction to Templates. The context:

Notice that instead of just saying:

friend iterator; // Make it a friend 

This code has:

friend class iterator; // Make it a friend

This is important because the name "iterator" is already in scope, from an included file.

What does Eckel really mean above? It seems friend iterator compiles correctly and I can't see the differences. Can anyone tell the answer? Thanks

jparthj
  • 1,606
  • 3
  • 20
  • 44
Alister
  • 71
  • 1

1 Answers1

6

As per C++03 standard section 11.4:

An elaborated-type-specifier shall be used in a friend declaration for a class.

So as per the specification the compiler will warn you that the friend declaration of iterator must be an elaborated class name. If not then the complier is non-compliant to the standard in this particular aspect.

What are Elaborated Type Specifiers?
C++ use elaborated type specifiers to tell the compiler explicitly to treat a class as a class. I think MSDN can explain it much better than I can, So check this out for detailed explanation.

Alok Save
  • 202,538
  • 53
  • 430
  • 533
  • Maybe an explanation on what `elaborated type specifier` means, because y'know, standardese isn't for everyone. :) – Xeo Jun 01 '11 at 04:04
  • @Xeo: Added a link to MSDN, I hope that shall suffice.:) – Alok Save Jun 01 '11 at 04:33
  • Also, in C++0x this restriction is lifted for template parameters, so we can now have `template class Final{ friend D; ~Final(){} };`. – Xeo Jun 01 '11 at 05:18