Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 相同的老故事-VS GCC 4.6.1_C++_Visual Studio 2010_Gcc4 - Fatal编程技术网

C++ 相同的老故事-VS GCC 4.6.1

C++ 相同的老故事-VS GCC 4.6.1,c++,visual-studio-2010,gcc4,C++,Visual Studio 2010,Gcc4,下面的代码可以使用VS2010进行编译,但无法使用gcc 4.6.1进行编译: 来自gcc的错误: *C:…\Calculator\u engine\u impl.h | 20 |错误:调用“(std::string{aka std::basic_string})不匹配(uu gnu cxx::u normal_iterator>&,u gnu cxx:u normal_iterator>)|* #包括“stdafx.h” #包括 #包括“Calculator_engine.h” int mai

下面的代码可以使用VS2010进行编译,但无法使用gcc 4.6.1进行编译:

来自gcc的错误:

*C:…\Calculator\u engine\u impl.h | 20 |错误:调用“(std::string{aka std::basic_string})不匹配(uu gnu cxx::u normal_iterator>&,u gnu cxx:u normal_iterator>)|*

#包括“stdafx.h”
#包括
#包括“Calculator_engine.h”
int main(int argc,字符**argv)
{
QString表达式(“1+2-3”);
auto beg=expression.begin();
auto-end=expression.end();
while(beg!=结束)
{

qDebut()您既有一个名为
term\uu
的函数,也有一个局部变量:

Int_T Calculator_engine<Int_T>::term_(Forward_Iterator& beg,Forward_Iterator& end)
//   ....

QString term_ = read_next_token_(beg,end);
//  ...  
result -= term_(beg,end);
Int\u T计算器\u引擎::术语(前向迭代器&beg,前向迭代器&end)
//   ....
QString term=读取下一个令牌(beg,end);
//  ...  
结果-=术语(beg,end);
GCC使用最内部的定义—在本例中是您的本地QString。然后它尝试找到一个
操作符()(QChar*&,QChar*&)
,以满足此调用,但失败了。显然visual studio做了一些不同的事情。我不完全确定哪个符合规范—但我怀疑GCC在这里得到了它


当然,解决方法是不要对局部变量和函数使用相同的名称。

我在源代码中没有看到任何对
QString
QChar
的引用。您确定发布了正确的位吗?@BlackBear行导致错误:result-=term\uz(beg,end);这是来自calculate fnc。@Irsmans是的,这是真的,引用的是char和string-这是VS版本。在代码::blocks中,我将version与QString和QChar一起使用。所以你没有发布导致错误的代码?我很困惑…你到底为什么要同时命名局部变量和函数
term\uuuu
?谢谢,是的,gcc I这很可能是对的。自从我开始使用gcc以来,我对VS编译的错误数量感到不知所措,gcc拒绝了这些错误。这是件好事。
Int_T Calculator_engine<Int_T>::term_(Forward_Iterator& beg,Forward_Iterator& end)
//   ....

QString term_ = read_next_token_(beg,end);
//  ...  
result -= term_(beg,end);