同样的故事——VS VS GCC 4.6.1
Same old story - VS vs GCC 4.6.1
下面的代码在VS2010中可以正常编译,但在gcc 4.6.1中无法编译:
来自gcc的错误:
*C:…Calculator_engine_impl.h|20|error: no match for call to '(std::string{又名std::basic_string}) (__gnu_cxx::__normal_iterator>&, __gnu_cxx::__normal_iterator>&)'|*
#include "stdafx.h"
#include <iostream>
#include "Calculator_engine.h"
int main(int argc, char** argv)
{
QString expression("1+2-3");
auto beg = expression.begin();
auto end = expression.end();
while (beg != end)
{
qDebut() <<
Calculator_engine<>::read_next_token_(beg,end);
}
}
#ifndef CALCULATOR_ENGINE_H
#define CALCULATOR_ENGINE_H
#include <string>
#include <cctype>
using namespace std;
//#include "Incorrect_Expression.h"
template<class Int_T = long long>
class Calculator_engine
{
private:
Calculator_engine();
static Int_T expression(QString exp);
template<class Forward_Iterator>
static Int_T term_(Forward_Iterator& beg,Forward_Iterator& end);
public:
template<class Forward_Iterator>
static QString read_next_token_(Forward_Iterator& beg,Forward_Iterator& end);
public:
static QString calculate(QString exp);
};
#include "Calculator_engine_impl.h"
#endif // CALCULATOR_ENGINE_H
#ifndef CALCULATOR_ENGINE_IMPL_H_INCLUDED
#define CALCULATOR_ENGINE_IMPL_H_INCLUDED
template<class Int_T>
class Calculator_engine;//[Forward decl]
template<class Int_T>
template<class Forward_Iterator>
Int_T Calculator_engine<Int_T>::term_(Forward_Iterator& beg,Forward_Iterator& end)
{
QChar token;
Int_T result;
switch(token)
{
case '*':
break;
case '/':
break;
}
}
template<class Int_T>
QString Calculator_engine<Int_T>::calculate(QString exp)
{
Int_T result;
auto beg = exp.begin();
auto end = exp.end();
while (beg != end)
{
QString term_ = read_next_token_(beg,end);
QChar token = read_next_token_(beg,end);
switch(token)
{
case '-':
result -= term_(beg,end);
break;
case '+':
result += term_(beg,end);
break;
}
}
}
template<class Int_T>
Int_T Calculator_engine<Int_T>::expression(QString exp)
{
}
template<class Int_T>
template<class Forward_Iterator>
QString Calculator_engine<Int_T>::read_next_token_(Forward_Iterator& beg,Forward_Iterator& end)
{
QString result;
while(std::isdigit(*beg))
{
}
return result;
}
#endif // CALCULATOR_ENGINE_IMPL_H_INCLUDED
您有一个名为term_
的函数和一个局部变量:
Int_T Calculator_engine<Int_T>::term_(Forward_Iterator& beg,Forward_Iterator& end)
// ....
QString term_ = read_next_token_(beg,end);
// ...
result -= term_(beg,end);
GCC使用最内层的定义——在本例中是您的本地QString。然后它尝试找到一个operator()(QChar*&, QChar*&)
来满足这个调用,但是失败了。显然visual studio做了一些不同的事情。我不完全确定哪个符合规范-但我怀疑GCC在这里得到了它。
当然,解决方案是局部变量和函数不要使用相同的名称。
相关文章:
- Visual C++: MSVC vs. GCC+CLANG: 处理 lambda 捕获类成员变量,正确的方法是什么?
- Clang vs GCC:枚举用法中的单冒号
- Clang vs GCC:挥发性访问的不同代码
- initializer_list and GCC 4.9.2 vs GCC trunk
- Clang vs GCC:可变参数λ捕获
- 如果Constexpr - clang vs.GCC,则非constexpr变量
- 在折叠表达式中使用 lambda 时"Uninitialized captured reference"错误 - clang vs gcc
- 使用 constexpr 函数的结果作为模板参数(clang vs gcc)
- CLANG VS GCC 模板子类在父级中使用前向声明的类
- clang vs gcc CRTP:constexpr 变量不能有非文字类型
- Glibc vs GCC vs binutils compatibility
- 在类嵌套静态常量成员变量初始化 Clang vs GCC 哪个编译器是正确的
- 在非“constexpr”上下文中的“constexpr”函数中使用lambda:clang vs gcc
- Clang vs GCC - 可变参数模板参数包后跟默认值参数在 GCC 4.8 中有效,但在 Clang 3.5 中无
- 模板专业化和DLL:Visual Studio vs. (GCC / Clang)
- Clang vs GCC vs MSVC模板转换操作符-哪个编译器是正确的
- Clang vs. GCC vs. MSVC中的SFINAE和可见性检查——这是正确的
- Clang vs GCC用于我的Linux开发项目
- vc++ vs GCC预处理器
- 同样的故事——VS VS GCC 4.6.1