C++ 非参数化构造函数上的模板类引发错误

C++ 非参数化构造函数上的模板类引发错误,c++,constructor,most-vexing-parse,parameterized-constructor,C++,Constructor,Most Vexing Parse,Parameterized Constructor,我有一个带有参数化构造函数的模板类 这里有一个最小的例子。以下代码可以正常工作: template <typename T> class my_template { public: my_template () {} my_template (T Value) : value(Value) {} T get_value () { return value; } private: int value; }; int main() { my_t

我有一个带有参数化构造函数的模板类

这里有一个最小的例子。以下代码可以正常工作:

template <typename T>
class my_template
{
public:
    my_template () {}
    my_template (T Value) : value(Value) {}
    T get_value () { return value; }

private:
    int value;
};

int main()
{
    my_template<int> int_thing (5);
    my_template<char> char_thing ('a');

    int int_test = int_thing.get_value ();
    char char_test = char_thing.get_value ();
}
在这一行:

  my_template<int> int_thing (5);
  int int_test = int_thing.get_value();
我一点雾也没有。从类中删除参数化构造函数不会影响在其他构造函数上引发的错误。C++只讨厌默认构造函数。 理论上,我可以在参数中抛出一些虚拟数据,稍后再更改,这样就不会阻塞我


但我必须知道。

这是一个函数声明(有关详细信息,请参阅):

my_template int_thing();
如果您的>c++11:

my_template<int> int_thing {};
my_template int_thing{};
否则,只需删除偏执

  int int_test = int_thing.get_value();
my_template<int> int_thing ();
my_template<int> int_thing {};