即使在boost库文件中模板参数的数量是正确的,编译器也会报错模板参数的数量

Compiler complains about wrong number of template arguments even if its correct in a boost library file

本文关键字:参数 编译器 文件 boost      更新时间:2023-10-16

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的文件,它工作得很好。谢谢您的回复。