c++ - 编译器提示模板参数的数量错误,即使它在 boost 库文件中是正确的

标签 c++ templates boost compiler-errors

boost 库中有一个名为 has_new_operator.hpp 的文件。当我使用 GCC 4.3.1 编译文件时出现以下错误

type_traits/has_new_operator.hpp:45: error: wrong number of template arguments (1, should be 2) type_traits/has_new_operator.hpp:24: error: provided for '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>在此代码之前。

Simulating your error .

Fixing your error .

关于c++ - 编译器提示模板参数的数量错误,即使它在 boost 库文件中是正确的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7089214/

相关文章:

c++ - boost split方法导致迭代器错误

c++ - (boost like) header only libraries 如何影响编译大小?

c++ - For 循环使程序 C++ 不断崩溃

来自 C++ 的 C# 回调提供访问冲突

c++ - std::enable_if 有条件地编译成员函数

模板参数的 C++ 部分类型推断 - 这可能吗?

c++ - 模板化类的非模板化接口(interface) C++

c++ - boost::spirit::qi 和访问冲突异常

c++ - 在 C++ 中处理字节顺序

c++ - C++中数组的参数大小