0
C++ 템플릿을 이해하기위한 연습을하고 있습니다. 내 의도는 템플릿 클래스의 기본 동작을 변경하는 함수 템플릿을 수행하는 것입니다.함수 템플릿 오류 - 선언되지 않았습니다.
나는 다음과 같은 오류 메시지를 얻을 : 단순화 된 파일은 다음과 같다
In file included from main.cpp:2:0:
test1.h: In function ‘int my::fun(char*, int)’:
test1.h:12:26: error: ‘my::T’ has not been declared
------ 파일 test1.h를 -------
#ifndef TEST_1_H
#define TEST_1_H
#include "test2.h"
namespace my
{
template <typename T = myclass>
int fun(char* str,int dim)
{
return my::T::fun(str,dim);
}
}
#endif
----- 파일 test2.h -------
#ifndef TEST_2_H
#define TEST_2_H
namespace my
{
struct myclass
{
static int fun(char* str,int dim);
};
}
#endif
------ 파일 test2.cpp --------
#include "test2.h"
namespace my
{
int myclass::fun(char* str,int dim)
{return 0;}
}
----- 파일 MAIN.CPP -------
#include "test2.h"
#include "test1.h"
int main()
{}
수 실수로 어디 있는지 알아 내도록 도와주세요?
미리 감사드립니다.
나는 새로운 표준을 사용하여 컴파일하려면 : 는 g ++ -std = C++ 11 test2.cpp의 MAIN.CPP – GTA
은 그냥 제거 내 :: before T. 템플릿 인수가 네임 스페이스에 저장되지 않습니다. –
안녕하세요 Coert, 잘 작동합니다. 대단히 감사합니다. 템플릿 인수를 사용할 때 결코 템플릿 인수를 정규화해야합니다. – GTA