   [C++] Access typedef in templated class
  Hi, the following code works:    class Function    {   typedef void (*FUNCTION)();    public:   FUNCTION function() const;   private:   FUNCTION _function;    }    Function::FUNCTION Function::function() const    {   return _function;    }But, the following doesn't! What is wrong? How can I fix this?    template<class T>    class Function    {   typedef void (*FUNCTION)(T *);    public:   FUNCTION function() const;   private:   FUNCTION _function;    }    template<class T>    Function::FUNCTION Function<T>::function() const // neither if I use Function<T>::FUNCTION ...    {   return _function;    }Thanks   
  typename Function<T>::FUNCTION   ;  Thanks, I never see when to use typenames...the errors the compiler gives aren't very clear that a typename keyword is missing :P   ;  Maybe you should try a different compiler. With MSVC 2008 you get:1>.\main.cpp(16) : warning C4346: 'Function<T>::FUNCTION' : dependent name is not a type1>   prefix with 'typename' to indicate a typeif you try compiling your code without typename. Seems pretty clear to me.   ;  And what about:    template<class T>    class Function    {   typedef void (*FUNCTION)(T *);    public:   const FUNCTION &function() const;   private:   FUNCTION _function;    }    template<class T>    const Function<T>::FUNCTION &Function<T>::function() const    {   return _function;    }Quote:Original post by SiCraneMaybe you should try a different compiler. With MSVC 2008 you get:1>.\main.cpp(16) : warning C4346: 'Function<T>::FUNCTION' : dependent name is not a type1>   prefix with 'typename' to indicate a typeif you try compiling your code without typename. Seems pretty clear to me.Yes, I use GCC. It's error messages are often rather vague I find.   ;Quote:Original post by DecriusAnd what about:And what about it?;  Hmm, been trying several combinations, but the one posted gives me:error: expected initializer before '&' tokenNot sure where, and if, to place the typename too.EDIT:Okay, got it almost working, let me figure this out ;-) (it's now only complaining for a class with 2 template items)...EDIT2:Got it! Thanks SiCrane!   ;  This part made me giggle:Quote:Function<T>::FUNCTION &Function<T>::function()It's pretty much the most readable code ever.Also, when I look at the word "Function" that many times, my mind starts trying to trick me into thinking that it's spelled wrong.   