Reputation: 520
I have a class template like Sample.hpp with type alias X.
#ifndef SAMPLE_HPP
#define SAMPLE_HPP
template<typename STA, typename STB>
class Sample
{
using X = Sample<STA,STB>;
public:
Sample();
inline X* GetNext() const;
private:
X* Next;
};
#include "Sample.cpp"
#endif // SAMPLE_HPP
And definitions are in Sample.cpp.
#include "Sample.hpp"
template<typename STA, typename STB>
Sample<STA,STB>::Sample() {
Next = nullptr;
}
template<typename STA, typename STB>
typename Sample<STA,STB>::X* Sample<STA,STB>::GetNext() const {
return this->Next;
}
My question is that, are there any others ways of defining GetNext function. For example without typename or without full declaration of Sample class template. When I change code to
template<typename STA, typename STB>
Sample<STA,STB>* Sample<STA,STB>::GetNext() const {
return this->Next;
}
It works, but I cant use type alias here directly , for example :
template<typename STA, typename STB>
X* Sample<STA,STB>::GetNext() const {
return this->Next;
}
Upvotes: 1
Views: 465
Reputation: 48938
You can use a trailing return type with the help of auto
:
template<typename STA, typename STB>
auto Sample<STA, STB>::GetNext() const -> X* {
return this->Next;
}
Upvotes: 5