Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在用C+模拟可变模板时,类中是否可以有不同的代码+;03?_C++_Templates_Emulation_Variadic Templates_C++03 - Fatal编程技术网

C++ 在用C+模拟可变模板时,类中是否可以有不同的代码+;03?

C++ 在用C+模拟可变模板时,类中是否可以有不同的代码+;03?,c++,templates,emulation,variadic-templates,c++03,C++,Templates,Emulation,Variadic Templates,C++03,我试图根据模板参数用不同的代码填充我的类,但得到一个编译错误。我的代码如下: #include <iostream> #include <string> struct EmptyType { }; template<class arg1=EmptyType, class arg2=EmptyType, class arg3=EmptyType> class my_class { my_class(){ s

我试图根据模板参数用不同的代码填充我的类,但得到一个编译错误。我的代码如下:

#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;
}
#包括
#包括
结构清空类型{};
模板
上我的课
{
我的班级(){

std::cout在实例化类的构造函数之前,需要将类的构造函数公开

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