编译器抱怨模板参数的数量错误,即使它在 boost 库文件中是正确的
boost库中有一个名为has_new_operator.hpp的文件。当我使用 GCC 4.3.1 编译文件时出现以下错误
type_traits/has_new_operator.hpp:45: 错误:模板编号错误 参数(1,应该是 2) type_traits/has_new_operator.hpp:24: 错误: 为“模板结构 boost::detail::test”提供
,它需要 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
);
There is a file in the boost library called has_new_operator.hpp. I am getting the following error when i complile the file using 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'
as per line 24 it expects 2 arguments and that is what is been passed in line 42. Also if you observe line 31, the same has been done but the compiler does not complain about it.
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
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来
std::size_t
对您当前的代码不可见。您可以在此代码之前尝试#include
。模拟您的错误。
修复您的错误。
It seems that
std::size_t
is not visible to your current code. You can try#include<iostream>
before this code.Simulating your error.
Fixing your error.
问题在于 std::nothrow_t (第 43 行)不可见。我在 std 命名空间中包含了一个包含 nothrow_t 的文件,并且它工作正常。感谢您的回复。
The problem is with std::nothrow_t (line:43) being not visible. I included a file which contained nothrow_t in the std namespace and it worked fine. Thanks for your responses.