0
템플릿 인수에 따라 클래스를 다른 코드로 채우려하지만 컴파일 오류가 발생합니다. 내 코드는 다음과 같다 :C++ 03로 Variadic 템플릿을 에뮬레이션 할 때 클래스에 다른 코드를 사용할 수 있습니까?
#include <iostream>
#include <string>
struct EmptyType { };
template<class arg1=EmptyType, class arg2=EmptyType, class arg3=EmptyType>
class my_class
{
my_class(){
std::cout << 3 << std::endl;
}
// FILL_MY_CLASS_DEFINE(3)
};
template<class arg1, class arg2>
class my_class<arg1,arg2,EmptyType>
{
my_class(){
std::cout << 2 << std::endl;
}
// FILL_MY_CLASS_DEFINE(2)
};
template<class arg1>
class my_class<arg1,EmptyType,EmptyType>
{
my_class(){
std::cout << 1 << std::endl;
}
};
template<>
class my_class<EmptyType,EmptyType,EmptyType>
{
// FILL_MY_CLASS_DEFINE(0)
};
int main(int argc, const char *argv[])
{
my_class<std::string, double, int> a;
my_class<std::string, int> b;
my_class<void> c;
//my_class d;
return 0;
}
나는 많은 오류를 얻을 :
prog.cpp: In function ‘int main(int, const char**)’:
prog.cpp:9: error: ‘my_class<arg1, arg2, arg3>::my_class() [with arg1 = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, arg2 = double, arg3 = int]’ is private
prog.cpp:38: error: within this context
prog.cpp:17: error: ‘my_class<arg1, arg2, EmptyType>::my_class() [with arg1 = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, arg2 = int]’ is private
prog.cpp:39: error: within this context
prog.cpp:25: error: ‘my_class<arg1, EmptyType, EmptyType>::my_class() [with arg1 = void]’ is private
prog.cpp:40: error: within this context
라이브 코드 here합니다. 그래서 궁금합니다 : Variable 템플릿을 C++ 03로 에뮬레이션 할 때 클래스 내에 다른 코드를 가질 수 있습니까?