Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference of friend iterator and friend class iterator which encounter in thinking in c++?

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

like image 650
Alister Avatar asked Jun 01 '11 03:06

Alister


1 Answers

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.

like image 106
Alok Save Avatar answered Oct 06 '22 07:10

Alok Save