2011-09-12 74 views
1

我試圖複製我的問題的最低限度的例子,用下面的代碼:編譯錯誤,而不是VisualStudio的

http://codepad.org/HjhNSk2S

它與Visual Studio 2008完美編譯,只顯示在鍵盤一些警告(關於初始化的順序),但失敗,G ++在Cygwin上,給下面的錯誤,我只是不知道爲什麼:

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>&) 

任何想法? 謝謝!

+1

如果你有一個帶有許多參數的構造函數,你應該考慮重構。另外,使用'typedef's!你的代碼會更容易閱讀。 –

+0

請發佈一個最小的代碼示例,說明您的實際問題中的問題,而不是鏈接到其他網站。 –

+0

錯誤發生在215行文件的第39行......這不是一個極簡主義的例子:-)嘗試在該行之後刪除大量代碼,並檢查是否仍然收到相同的錯誤消息。 – user9876

回答

4

使用以下劃線後跟大寫字母開頭的標識符是非法的,例如, _B在線39.

編譯器有可能#define d是一個積分常數,這將解釋您的錯誤。嘗試將其更改爲有效的標識符。

+0

太好了,非常感謝!我不知道,現在編譯好:) – WhitAngl

+2

@WhitAngl:在標識符中的任何位置使用雙下劃線也是非法的。你在這裏沒有這樣做,但很高興知道:-) –

+2

@Peter:另外,如果在全局命名空間中使用該標識符,則命名一個以單個下劃線和小寫字母開頭的標識符也是非法的。這完成了三個限制:) –