I have a template class with the following structure
//CFoo.hpp (header file)
template <typename T>
class CFoo {
struct SFoo {
T *ptr;
/* rest is irrelevant */
} *foo;
public:
/* omitting irrelevant parts */
SFoo* get();
};
Now, if I implement the method SFoo* get() inside header file everything works nice. However, if I separate declaration and definition my code stops working with the followingg compilation errors.
//CFoo.cpp (source code, example 1)
/* omitting irrelevant parts */
template <typename T>
SFoo* CFoo<T>::get() { return foo; } //ERROR HERE
Error: <where-is-the-error>: error: ‘SFoo’ does not name a type
//CFoo.cpp (source code, example 2)
/* omitting irrelevant parts */
template <typename T>
CFoo<T>::SFoo* CFoo<T>::get() { return foo; } //ERROR HERE
Error: <where-is-the-error>: error: need ‘typename’ before ‘CFoo<T>::SFoo’ because ‘CFoo<T>’ is a dependent scope
I'm looking forward to any hints on how to fix that. Thanks in advance.