【问题标题】:compile error on g++ and not VisualStudio在 g++ 而不是 VisualStudio 上编译错误
【发布时间】:2011-09-12 15:55:56
【问题描述】:

我尝试使用以下代码复制我的问题的一个极简示例:

http://codepad.org/HjhNSk2S

它确实与 Visual Studio 2008 完美编译,只是在键盘上显示一些警告(关于初始化的顺序),但在 cygwin 上使用 g++ 失败,给出以下错误,我不知道为什么:

Interpolator2.cpp:39: error: expected ‘,’ or ‘...’ before numeric constant
Interpolator2.cpp: In constructor ‘Interpolator<DIM, SAMPLESTYPE>::Interpolator(const std::vector<Vector<DIM, SAMPLESTYPE>, std::allocator<Vector<DIM, SAMPLESTYPE> > >&, const std::vector<double, std::allocator<double> >&, const std::vector<Vector<DIM, SAMPLESTYPE>, std::allocator<Vector<DIM, SAMPLESTYPE> > >&)’:
Interpolator2.cpp:45: error: ‘_wB’ was not declared in this scope
Interpolator2.cpp:46: error: ‘_sqrDist’ was not declared in this scope
Interpolator2.cpp:47: error: ‘_kernel’ was not declared in this scope
Interpolator2.cpp:48: error: ‘_interpolateBins’ was not declared in this scope
Interpolator2.cpp:49: error: ‘_kNNDist’ was not declared in this scope
Interpolator2.cpp:50: error: ‘_NLevels’ was not declared in this scope
Interpolator2.cpp: At global scope:
Interpolator2.cpp:131: error: expected ‘,’ or ‘...’ before numeric constant
Interpolator2.cpp: In constructor ‘InterpModeData<DIM, SAMPLESTYPE>::InterpModeData(int, double, const std::vector<std::vector<TsFlow, std::allocator<TsFlow> >, std::allocator<std::vector<TsFlow, std::allocator<TsFlow> > > >&, Vector<DIM, SAMPLESTYPE> (*)(const Vector<DIM, SAMPLESTYPE>&, const Vector<DIM, SAMPLESTYPE>&, double), std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, double (*)(const Vector<DIM, SAMPLESTYPE>&, const Vector<DIM, SAMPLESTYPE>&, double), const std::vector<double, std::allocator<double> >&, const std::vector<double, std::allocator<double> >&, const std::vector<Vector<DIM, SAMPLESTYPE>, std::allocator<Vector<DIM, SAMPLESTYPE> > >&, const std::vector<Vector<DIM, SAMPLESTYPE>, std::allocator<Vector<DIM, SAMPLESTYPE> > >&)’:
Interpolator2.cpp:135: error: ‘_sumWA’ was not declared in this scope
Interpolator2.cpp:135: error: ‘_sumWB’ was not declared in this scope
Interpolator2.cpp:135: error: ‘_samples’ was not declared in this scope
Interpolator2.cpp: In function ‘int main()’:
Interpolator2.cpp:206: error: no matching function for call to ‘Interpolator<2, double>::Interpolator(std::vector<Vector<2, double>, std::allocator<Vector<2, double> > >&, std::vector<double, std::allocator<double> >&, std::vector<Vector<2, double>, std::allocator<Vector<2, double> > >&, std::vector<double, std::allocator<double> >&, <unresolved overloaded function type>, <unresolved overloaded function type>, <unresolved overloaded function type>, int, int)’
Interpolator2.cpp:43: note: candidates are: Interpolator<DIM, SAMPLESTYPE>::Interpolator(const std::vector<Vector<DIM, SAMPLESTYPE>, std::allocator<Vector<DIM, SAMPLESTYPE> > >&, const std::vector<double, std::allocator<double> >&, const std::vector<Vector<DIM, SAMPLESTYPE>, std::allocator<Vector<DIM, SAMPLESTYPE> > >&) [with int DIM = 2, SAMPLESTYPE = double]
Interpolator2.cpp:36: note:                 Interpolator<2, double>::Interpolator(const Interpolator<2, double>&)
Interpolator2.cpp: In member function ‘void Interpolator<DIM, SAMPLESTYPE>::interpolate(double, const std::vector<Vector<DIM, SAMPLESTYPE>, std::allocator<Vector<DIM, SAMPLESTYPE> > >&, std::vector<double, std::allocator<double> >&) [with int DIM = 2, SAMPLESTYPE = double]’:
Interpolator2.cpp:212:   instantiated from here
Interpolator2.cpp:58: error: no matching function for call to ‘InterpModeData<2, double>::InterpModeData(unsigned int&, double&, std::vector<std::vector<TsFlow, std::allocator<TsFlow> >, std::allocator<std::vector<TsFlow, std::allocator<TsFlow> > > >&, Vector<2, double> (*&)(const Vector<2, double>&, const Vector<2, double>&, double), std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, double (*&)(const Vector<2, double>&, const Vector<2, double>&, double), std::vector<double, std::allocator<double> >&, std::vector<double, std::allocator<double> >&, std::vector<Vector<2, double>, std::allocator<Vector<2, double> > >&, std::vector<Vector<2, double>, std::allocator<Vector<2, double> > >&, std::vector<double, std::allocator<double> >&, std::vector<double, std::allocator<double> >&, const std::vector<Vector<2, double>, std::allocator<Vector<2, double> > >&)’
Interpolator2.cpp:133: note: candidates are: InterpModeData<DIM, SAMPLESTYPE>::InterpModeData(int, double, const std::vector<std::vector<TsFlow, std::allocator<TsFlow> >, std::allocator<std::vector<TsFlow, std::allocator<TsFlow> > > >&, Vector<DIM, SAMPLESTYPE> (*)(const Vector<DIM, SAMPLESTYPE>&, const Vector<DIM, SAMPLESTYPE>&, double), std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >&, double (*)(const Vector<DIM, SAMPLESTYPE>&, const Vector<DIM, SAMPLESTYPE>&, double), const std::vector<double, std::allocator<double> >&, const std::vector<double, std::allocator<double> >&, const std::vector<Vector<DIM, SAMPLESTYPE>, std::allocator<Vector<DIM, SAMPLESTYPE> > >&, const std::vector<Vector<DIM, SAMPLESTYPE>, std::allocator<Vector<DIM, SAMPLESTYPE> > >&) [with int DIM = 2, SAMPLESTYPE = double]
Interpolator2.cpp:127: note:                 InterpModeData<2, double>::InterpModeData(const InterpModeData<2, double>&)

有什么想法吗? 谢谢!!

【问题讨论】:

  • 如果你的构造函数有这么多参数,你应该考虑重构。另外,请使用typedefs!你的代码会更容易阅读。
  • 请发布一个最小的代码示例,在您的实际问题中说明问题,而不是链接到另一个站点。
  • 错误出现在 215 行文件的第 39 行...这不是一个极简示例 :-) 尝试在该行之后删除很多代码,并检查您是否仍然得到相同错误信息。
  • 这 200 行是从一个 1000 多行的文件中提取的,以说明问题...我会尝试删除更多
  • (PS 要清楚,重要的错误始终是第一个错误。其余的可能正在发生,因为编译器被第一个错误弄糊涂了。因此,请获取“预期”的最小示例, ' or '...' before numeric constant" 错误)

标签: c++ gcc compiler-errors


【解决方案1】:

使用以下划线后跟大写字母开头的标识符是非法的,例如_B 第 39 行。

编译器可能将#defined 作为一个整数常量,这可以解释您的错误。尝试将其更改为有效的标识符。

【讨论】:

  • 太好了,非常感谢!我不知道,现在它编译得很好:)
  • @WhitAngl:在标识符的任何地方使用双下划线也是非法的。你没有在这里做,但很高兴知道:-)
  • @Peter:此外,如果在全局命名空间中使用标识符,那么以单个下划线和小写字母开头的标识符也是非法的。这完成了三个限制:)
  • @David:谢谢,我不知道那个:)
猜你喜欢
  • 2012-10-06
  • 1970-01-01
  • 1970-01-01
  • 2015-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多