Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.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++ - Fatal编程技术网

C++ 如何引发“模板参数”类型的异常?

C++ 如何引发“模板参数”类型的异常?,c++,C++,我的模板标题如下所示: template<class TypeA, size_t tsize=100, class Exc=std::out_of_range> 我收到以下错误消息: error: expected primary-expression before ‘e’ throw Exc e; 我做错了什么?根据,表达式throw需要另一个表达式 但您提供的抛出表达式带有声明,声明不是表达式 试一试 或 正如贾斯汀对你的问题所建议的那样。抛出Exc{message};你希望

我的模板标题如下所示:

template<class TypeA, size_t tsize=100, class Exc=std::out_of_range>
我收到以下错误消息:

error: expected primary-expression before ‘e’
throw Exc e;
我做错了什么?

根据,表达式throw需要另一个表达式

但您提供的抛出表达式带有声明,声明不是表达式

试一试


正如贾斯汀对你的问题所建议的那样。

抛出Exc{message};你希望e在掷骰中做什么?为什么要用花括号?从那个以后,它对我来说很好,我从来并没有见过这样的表达式,它也是这样的构造函数调用吗?我忘了提到s,你们可以同时使用{}s和s。如果有一个类具有匹配的参数,则可以使用调用该类的构造函数。使用大括号创建即时消息称为“列表初始化”。查看详细信息。
error: expected primary-expression before ‘e’
throw Exc e;
Exc e{"message"};
throw e;
throw Exc{"message"};