0
C++ Return Type Error Please Help
template <typename T> class ClassOne { typedef std::list<classA> pos; pos All(); } How can I define function All out side class I try ( template<typename T> ClassOne<T>::pos ClassOne<T>::All() { } ) And I run into some kind of return issue HELP!!!!!!!!!!!!!!!
5 Answers
+ 4
Due to lookup problems with dependent types, the language specifies that in general a dependent qualified name does not denote a type unless prefixed by the typename keyword.
Since the scope ClassOne< T > is dependent on the template parameter, the type ClassOne< T >::pos falls under this category, despite "pos" not being dependent itself. Therefore, you need to prefix it with typename in the function definition, i.e.
template < typename T >
typename ClassOne< T >::pos ClassOne< T >::All() {}
Read through this thread for more information about when to use typename:
https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
It might lead you deep down into the rabbit hole that C++ templates really are. You have been warned.
+ 2
https://code.sololearn.com/cvWOswb6Om3c/?ref=app
Take a look.
+ 1
CarrieForle lol, I just wrote the same.
0
I don't quite understand what you mean. You mean something like this?
https://code.sololearn.com/cHB8cuGhyL58/?ref=app
0
U have no idea, how u just saved me from 3 days headache
TAHNKYOU ALL!!!!!!!!!!!!!!!!!
Keep up a good work guys!!
Dame!! it feel good to shut compiler mouth