[완료] 템플릿 클래스 내부 타입을 쓰고 싶습니다. (typename)

purewell의 이미지

#include <iostream>
using namespace std;
 
template<typename T>
class CTest
{
public:
    typedef T   type;
 
    type& getWhat(type& t);
};
 
template<typename T>
CTest<T>::type&
CTest<T>::getWhat(CTest::type& t)
{
    return t;
}

위 코드에서 아래에 메서드 정의하는 부분에서 에러가 떨어집니다.
tmpl.cpp:14: error: `template class CTest' used without template parameters
tmpl.cpp:14: error: expected constructor, destructor, or type conversion before '&' token
tmpl.cpp:14: error: expected `;' before '&' token

템플릿 클래스 안에 정의한 타입을 외부에서 메서드 정의할 때 쓰고자할 땐 어떻게해야하나요?

imyejin의 이미지

seoleda의 이미지

어떤 컴파일러를 사용하셨나요?
gcc 3.3에서는 다음과 같은 경고가 나오지만 컴파일은 됩니다.

template.cpp:14: warning: `CTest<T>::type' is implicitly a typename
template.cpp:14: warning: implicit typename is deprecated, please see the
   documentation for details

익명사용자의 이미지

가타입의 static member 이름인지 type 이름인지
판단할 수 없다는 메세지입니다.
typename을 붙여서 명시하세요.