vc 2010运行C语言程序错误,这是VC 2010编译器的错误吗?

使用Visual Studio 2010 SP1:

#include

//namespace XXX {

struct Test

{

bool operator==(const Test& r) const { return true; }

};

//}

//typedef XXX::Test Test;

template inline bool operator!=(const T& l,const T& r)

{ return !(l==r); }

int main()

{

std::vector vt;

std::vector vt2 = std::move(vt);

return 0;

}

如果我按原样编译上面的代码,它会失败并显示以下错误:

1>C:\apps\MVS10\VC\include\vector(609): error C2593: 'operator !=' is ambiguous

1> C:\apps\MVS10\VC\include\xmemory(268): could be 'bool std::operator !=<_ty>(const std::allocator<_ty> &,const std::allocator<_ty> &) throw()'

1> with

1> [

1> _Ty=Test

1> ]

1> test.cpp(11): or 'bool operator !=<:allocator>>(const T &,const T &)' [found using argument-dependent lookup]

1> with

1> [

1> _Ty=Test,1> T=std::allocator

1> ]

1> while trying to match the argument list '(std::allocator<_ty>,std::allocator<_ty>)'

1> with

1> [

1> _Ty=Test

1> ]

1> C:\apps\MVS10\VC\include\vector(606) : while compiling class template member function 'void std::vector<_ty>::_Assign_rv(std::vector<_ty> &&)'

1> with

1> [

1> _Ty=Test

1> ]

… vector(609)解析为此行:

else if (get_allocator() != _Right.get_allocator())

OTOH,如果我取消注释名称空间与XXX相关的行,它会毫无怨言地编译.

我不得不认为这是一个编译器错误,但我正在寻找一些独立的验证.

编辑:只是作为解释,我第一次使用VS2010重新编译一些旧代码时遇到了这种情况.全球操作符从过去几年开始(现已删除).我只是无法理解为什么有些代码失败而其他代码没有.上面的代码是我对失败案例的精炼(显然,旧代码不会包含对std :: move()的调用).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值