프로그래밍/의문

explicit specialization of 'function name' in class

제페 2018. 5. 1. 21:08
반응형

클래스 안에서 '함수 이름'의 명시적인 특수화를 했습니다.


윈도우 x64에선 발생하지 않았으나 닌텐도 플랫폼 설정으로 빌드 시 발생했다.

템플릿 특수화 함수의 정의가 class 안에 있어서 발생하는 오류 메세지이다.

예를 들면 다음과 같은 코드일 때 해당 에러가 발생할 수 있다.


class Foo
{
public:
template < typename Type >
Type GetValue() const
{
return Type{};
}

template<>
std::string GetValue() const
{
return std::string{};
}
};



다음 코드처럼 정의를 외부로 빼서 오류를 해결했다.


class Foo
{
public:
template < typename Type >
Type GetValue() const
{
return Type{};
}

template<>
std::string GetValue() const;
};

template<>
std::string Foo::GetValue() const
{
return std::string{};
}



반응형