即使在boost库文件中模板参数的数量是正确的,编译器也会报错模板参数的数量
Compiler complains about wrong number of template arguments even if its correct in a boost library file
boost库中有一个名为has_new_operator.hpp的文件。当我使用GCC 4.3.1
编译文件时,我得到以下错误type_traits/has_new_operator.hpp:45: error:错误的模板数type_traits/has_new_operator.hpp:24:错误:提供给'template struct boost::detail::test'
按照第24行,它需要2个参数,这就是第42行传递的参数。同样,如果你观察第31行,同样的操作已经完成,但是编译器没有报错。
21: namespace boost {
22: namespace detail {
23: template <class U, U x>
24: struct test;
25:
26: template <typename T>
27: struct has_new_operator_impl {
28: template<class U>
29: static type_traits::yes_type check_sig1(
30: U*,
31: test<
32: void *(*)(std::size_t),
33: &U::operator new
34: >* = NULL
35: );
36: template<class U>
37: static type_traits::no_type check_sig1(...);
39: template<class U>
40: static type_traits::yes_type check_sig2(
41: U*,
42: test<
43: void *(*)(std::size_t, const std::nothrow_t&),
44: &U::operator new
45: >* = NULL
);
似乎std::size_t
对您当前的代码不可见。您可以在此代码之前尝试#include<iostream>
。
模拟你的错误。
修复错误
问题在于std::nothrow_t (line:43)不可见。我在std名称空间中包含了一个包含nothrow_t的文件,它工作得很好。谢谢您的回复。
相关文章:
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- 告诉c++编译器该参数没有别名
- 我收到同义重复编译器错误。我应该如何修复"类型"X"的参数与类型"X"的参数不兼容?
- 推断模板参数的编译器
- 有没有办法在从编译器获取参数时避免预处理器宏?
- 当简单捕获中的标识符显示为参数的声明符 ID 时,没有编译器诊断
- 模板模板参数和模板别名:编译器错误?
- 如果可推导类型上有替换,可变参数模板类型推导会使编译器崩溃
- 如何使用传递给编译器的相同参数在 cmake 中运行命令?
- 编译器是否强制根据模板参数计算表达式?
- C++自定义分配器大小参数作为模板参数会引发编译器错误
- 为什么编译器抱怨 std::thread 参数在转换为右值后必须是可调用的?
- 编译器在C++中调用另一个函数时,在参数中查找已删除的构造函数
- 编译器给出错误:format 指定类型 'float *',但参数的类型'double' [-Wformat]
- 编译器确定参数是给定还是省略
- 当作为参数传入时,是否可以由编译器指定模板类参数?
- 在没有对象参数编译器错误的情况下调用非静态成员函数
- 默认模板参数编译器错误
- 缺少默认参数-编译器错误