[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problems with g++ 4.0.2 (templates, friends and inheritance)
From: |
Maurizio Loreti |
Subject: |
Re: Problems with g++ 4.0.2 (templates, friends and inheritance) |
Date: |
02 Dec 2005 17:53:13 +0100 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |
Emanuel Ziegler <eziegler@web.de> writes:
> compiled without any problems before, it now gives the errors
> error: 'get_test' is neither function nor member function; cannot be
> declared friend
well, the diagnostic is clear; g++ needs a prototype in scope of the
function to be declared friend. the followign compiles correctly:
,-----
| template <class T> class FriendClass;
|
| template <class T> T get_test (const FriendClass<T> &fc) {
| return fc.test; }
|
| template <class T> class FriendClass {
| friend T get_test<T> (const FriendClass<T> &);
| protected:
| T test;
| };
|
| int main () {
| FriendClass<int> fc;
| get_test(fc);
| return 0;
| }
`-----
for your second problem, have a look to the point 2 of the "C++
templates FAQ" at http://womble.decadentplace.org.uk/c++/template-faq.html
--
Maurizio Loreti http://www.pd.infn.it/~loreti/mlo.html
Dept. of Physics, Univ. of Padova, Italy ROT13: ybergv@cq.vasa.vg