我有一大堆ccc代碼和一些C++代碼的.cc文件的大項目。我想在這個程序中使用一個向量,因爲我需要一個無限制的數據類型,這個數據類型很容易讓2d(換句話說,我不想使用數組或列表)。 問題是,當我在包含矢量類後運行make時,出現了以前沒有得到的錯誤。唯一的區別是#include <vector>
。我沒有編寫make文件(其中大約有4個或5個),但據我所知,它使用的是GNU編譯器。我沒有實例化矢量對象,已經包含using namespace std;
,並且當我註釋掉矢量的include指令時,錯誤消失。在這個項目的另一個文件中,我使用了隊列庫,它沒有任何問題。問題發生在我將它包含在.h文件中時,它對.cc文件沒有問題,但是因爲我需要在.h文件中實例化矢量對象,所以我沒有使用.cc文件的商品爲了這。有人可以幫我解決這個問題嗎?鏈接矢量類的問題
這裏是bash的粘貼的,導致錯誤產生的部分輸出複製:
g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads/main.cc
g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads
/scheduler.cc
g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads/synch.cc
g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads
/system.cc
g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads
/thread.cc
g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads
/threadtest.cc
g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../machine
/interrupt.cc
g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../machine
/sysdep.cc
In file included from /usr/include/c++/4.4/vector:61,
from ../threads/system.h:19,
from ../machine/sysdep.cc:77:
/usr/include/c++/4.4/bits/stl_algobase.h:232:56: error: macro "min" passed 3 arguments,
but takes just 2
/usr/include/c++/4.4/bits/stl_algobase.h:253:56: error: macro "max" passed 3 arguments,
but takes just 2
In file included from /usr/include/c++/4.4/vector:61,
from ../threads/system.h:19,
from ../machine/sysdep.cc:77:
/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected unqualified-id before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected ‘)’ before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected ‘)’ before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected ‘)’ before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected initializer before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected unqualified-id before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected ‘)’ before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected ‘)’ before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected ‘)’ before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected initializer before ‘const’
/usr/include/c++/4.4/bits/stl_algobase.h:232: error: ‘std::min’ declared as an ‘inline’
variable
/usr/include/c++/4.4/bits/stl_algobase.h:232: error: template declaration of ‘const _Tp&
std::min’
/usr/include/c++/4.4/bits/stl_algobase.h:235: error: expected primary-expression before
‘if’
/usr/include/c++/4.4/bits/stl_algobase.h:235: error: expected ‘}’ before ‘if’
/usr/include/c++/4.4/bits/stl_algobase.h:237: error: expected unqualified-id before
‘return’
/usr/include/c++/4.4/bits/stl_algobase.h:253: error: ‘max’ declared as an ‘inline’ variable
/usr/include/c++/4.4/bits/stl_algobase.h:253: error: template declaration of ‘const _Tp&
max’
/usr/include/c++/4.4/bits/stl_algobase.h:256: error: expected primary-expression before
‘if’
/usr/include/c++/4.4/bits/stl_algobase.h:256: error: expected ‘}’ before ‘if’
/usr/include/c++/4.4/bits/stl_algobase.h:258: error: expected unqualified-id before
‘return’
/usr/include/c++/4.4/bits/stl_algobase.h:259: error: expected declaration before ‘}’ token
make[1]: *** [sysdep.o] Error 1
make[1]: Leaving directory `/home/f85/njvanbal/workspace/nachos2/userprog'
make: *** [all] Error 2
@ user381261:宏是邪惡的。你顯然聽說過這個。現在你有一個證明。如果您必須使用宏,只需將它們命名爲WITH_LONG_UGLY_NAMES,以儘量減少它們被定義的可能性。命名空間並不會幫助,因爲宏不遵守範圍......爲什麼人們不會盲目地遵循諸如「不要使用宏,除非必須」這樣的好建議 – 2010-10-24 16:49:36
我沒有寫這個項目,我是不允許修改這些宏所在的代碼,但我將確保在將來記住您的建議。 – user381261 2010-10-24 18:20:55
有人寫了宏calles'min'和'max',並把它們放在你不允許修改的頭文件中?這值得thedailywtf.com。 – Beta 2010-10-25 12:26:35