gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:12:56 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com