以下代码使用 32 位编译器在 C++Builder XE7 中产生错误:
#include <utility>
#include <boost/any.hpp>
std::pair< int, boost::any > y;
void test()
{
y = std::pair< int, boost::any >( 1, 2 ); // error!
}
错误是:
"Could not find a match for 'operator std::pair<int,boost::any>::=(std::pair<int,boost::any>)'"
我不明白。这段代码本质上没有任何问题,它在(很多)较旧的编译器中编译得很好。现在这里有一些有趣的地方:
1)64位编译器编译代码没有错误
2) 如果我将对的第二种类型从 'boost::any' 更改为内置类型,例如 'int',则代码编译不会出错
作为一种解决方法,我能够做到这一点:
#include <utility>
#include <boost/any.hpp>
std::pair< int, boost::any > y;
void test()
{
std::pair< int, boost::any > temp = std::pair< int, boost::any >( 1, 2 );
y = temp;
}
它的效率较低,但它让我绕过了编译器错误。
直到最近,我一直在使用过时的 C++ 编译器 (C++Builder 5/6),所以我还没有跟上 C++ 标准和 C++11 的变化。因此,我可能不知道导致此代码无效的语言更改。那么,有人可以告诉我这个编译器错误是语言更改的结果,还是编译器错误?
谢谢,
丹尼斯