Emanuel Ziegler <[EMAIL PROTECTED]> writes: > template <class T> > class FriendClass > { > // This line causes trouble > friend T get_test<T> (const FriendClass &); > protected: > T test; > }; > > template <class T> > T get_test (const FriendClass<T> &fc) > { > return fc.test; > } > > int main () > { > FriendClass<int> fc; > get_test(fc); > return 0; > } > > --->8--- > > compiled without any problems before, it now gives the errors > error: 'get_test' is neither function nor member function; cannot > be declared friend > error: expected ';' before '<' token > in 4.0.2. But I'm pretty sure it's valid C++ code.
I'm pretty sure it isn't. Declare get_test before FriendClass and you should be fine: template <class T> class FriendClass; template <class T> T get_test (const FriendClass<T> &); template <class T> class FriendClass { // This line causes trouble friend T get_test<> (const FriendClass &); ... > Another problem concerns inheritance. Although members are declared > protected and inheritance is public, the members are not transferred > into the scope of the derived class: > > ---8<--- > > template <class T> > class Base > { > protected: > int test; > }; > > template <class T> > class Derived : public Base<T> > { > protected: > // This doesn't work > /* using namespace Base<T>; */ > // This works but should be useless and is unhandy > using Base<T>::test; Indeed. > void set_test () > { > test = 0; The compiler is correct again. For some T's, there might be a specialization for Base<T> that doesn't declare a member test. The (apparent) Base class template is therefore not considered when the name test is looked up. If you write this->test = 0; , test becomes a dependant name, which causes its lookup to be defered to instantiation time. At that time, the inherited test will be taken into consideration. > Anyone else experienced similar problems? Certainly. _______________________________________________ Help-gplusplus mailing list Help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus