2014-03-04 3 views
-1

으로지도 :템플릿 표준 : I 클래스 멤버로이 같은 뭔가가 필요 클래스 멤버

std::map<std::string, std::map<std::string, template<class> T>> m_map; 

오류 메시지 :

누군가가 나에게이 문제를 해결하는 데 도움이 될 수 있습니다 template is not allowed를?

들으

+1

당신은 당신이 말하고자하는 것을 설명 할 수? 그것은 의미가 없습니다. –

+0

'T'를 두 번째 내부 템플릿 인자로 사용하는 것입니까? –

+0

네,이 템플릿은 무엇입니까 거기 :) –

답변

0

std::map<> 예상하는 (콘크리트) 인수를 입력하지만, template<class> Tstd::map<std::string, template<class> T>>이 유형 아니라고 다음, 유형이 아닙니다.

"이와 비슷한 것"은 불행히도 충분한 사양이 아닙니다.

당신이 정말로 "(T로 문자열의지도)에지도 문자열"을 의미하는 경우 다음 적절한, 재사용 가능한 솔루션이 될 것입니다 다음

// Declare a template type "map of string to (map of string to T)" 
template <typename T> 
using foobar = std::map<std::string, std::map<std::string, T>>; 

.... 

foobar<int> frob; 

http://ideone.com/YZ6FRa를 참조하십시오. 회원이 한 번 촬영으로

이도 할 수있다 :

template <typename T> 
class Foobar { 
    std::map<std::string, std::map<std::string, T>> m_map; 
}; 
1

당신은지도의 선언에서 template<class>을 제거 할 수 있습니다.

template<class T> 
class A 
{ 
    std::map<std::string, std::map<std::string, T>> m_map; 
}; 
0

당신은 클래스 템플릿 매개 변수, std::map 실제로이 기본값이 네 개의 템플릿 인수를 필요로 std::map을하려는 경우.

#include <map> 

template <template <typename, typename, typename, typename> class T> 
void func() 
{ 
} 

int main() 
{ 
    func<std::map>(); 
} 

그럼 당신은 그것을 형식 정의를 할 수 있습니다

typedef T<std::string, int, std::less<std::string>, std::allocator<std::pair<const std::string, int>>> my_map; 

(선택적 std::stringint 당신이 FUNC에 따라서 통과 템플릿 매개 변수입니다.)