2012年3月13日 星期二

error: ‘vector’ has not been declared

佛力沙!我生氣啦!!!


再寫程式時,本來沒有問題的,結果加了vector以後就一直出問題……
感謝全知全能的Google老師幫我找到解答

以下是我在Makefile時的Error Message:
In file included from ./MyCode.cpp:8:
./MyCode.h:41: error: ‘vector’ has not been declared
./MyCode.h:41: error: expected ‘,’ or ‘...’ before ‘<’ token
./MyCode.cpp:108: error: prototype for ‘void Core::makeLine(Point, Point, std::vector<Point, std::allocator<Point> >*)’ does not match any in class ‘Core’
./MyCode.h:41: error: candidate is: void Core::makeLine(Point, Point, int)

Point是我程式裡面的一個Class,所以就別理了……
把Error Message丟給Google後就找到原因了
只要.h都加上下面這行代碼即可:
using namespace std;
當然,勤勞點的話,也可以把你的代碼改成
makeLine(Point a, Point b, std::vector<Point> *line)

簡單說就是using namespace和#include用法是一樣的……

參考資料:
"FAILURE is the FIRST STEP towards SUCCESS": namespace - error: 'vector' has not been declared, 'cout' was not declared in this scope

沒有留言:

張貼留言