I have a big project w开发者_高级运维ith a bunch of .cc files that have mostly c code and some c++ code. I want to use a vector in this program since I need an unbounded data type that is simple to make 2d (in other words I don't want to use an array or a list).
The problem is that when I run my make after including the vector class I get errors that I didn't get before. The only line that makes any difference is #include <vector>
. I did not write the make files (and there are about 4 or 5 of them) but to the best of my knowledge it is using the GNU compiler. I have no vector objects instantiated, already included using namespace std;
and the error goes away when I comment out the include directive for vector. On another file in this project however I used the queue library and it didn't have any problem with it. The problem happens when I include it in a .h file, it has no problem with .cc files, but since I will need to instantiate a vector object in the .h file I don't have the commodity of only using .cc files for this. Can someone give me any help for this problem?
Here is the output copied pasted from bash for the part that leads up to the error:
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
Always best to look back to the first error first; in your case:
/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
Looks like you have defined a macro (or maybe a function) called min
and max
in your own code. The #include
for vector
apparently also defines a macro for min
and max
and the compiler is getting confused. Change the name of your min
and max
macros.
精彩评论