This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/19188] friend funtion inside a template class seems to have a problem
- From: "lerdsuwa at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 31 Dec 2004 13:23:03 -0000
- Subject: [Bug c++/19188] friend funtion inside a template class seems to have a problem
- References: <20041229134715.19188.max656@hotmail.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From lerdsuwa at gcc dot gnu dot org 2004-12-31 13:23 -------
The 'typename' keyword is required because later C++ introduces a lot more
features. Those that interfere with your code are partial specialization
and specialization. For example, you can now have specialization
template <> class tstack<bool> {
int link;
...
};
Then when you declare
tstack<bool> t;
it will use the above declaration, where 'link' is now a member data
instead of a nested class. So the code
tstack<T>::link* p;
which could be interpreted as declaring a variable which is a pointer to type
'tstack<T>::link' if 'T' is 'int'. But when 'T' is 'bool' it could means
multiplying a member data with another variable named 'p'.
To resolve the ambiguity, later C++ requires the 'typename' keyword to
treat as pointer declaration, otherwise it will be treated as muliplication.
Older C++ books don't have this 'typename' keyword but newer good books
from respected authors coming out in the last few years should.
(Many new C++ books are still wrong).
I know the parser error message could be improved, and there are plenty of
bug reports elsewhere about it.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19188