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!!!!!!!!!!!!!!!

20th Nov 2020, 7:37 AM
Eyob
Eyob - avatar
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.
20th Nov 2020, 8:45 AM
Shadow
Shadow - avatar
20th Nov 2020, 8:21 AM
Akib
Akib - avatar
+ 1
CarrieForle lol, I just wrote the same.
20th Nov 2020, 8:22 AM
Akib
Akib - avatar
0
I don't quite understand what you mean. You mean something like this? https://code.sololearn.com/cHB8cuGhyL58/?ref=app
20th Nov 2020, 8:21 AM
㊠æČč æˆ‘ć…ˆäž‹äș†
㊠æČč æˆ‘ć…ˆäž‹äș† - avatar
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
20th Nov 2020, 9:52 AM
Eyob
Eyob - avatar