Strange compile errors when merely including <map>

C

Carl Youngblood

I recognize that I may not be giving sufficient information with this,
but in the interest of not bogging the list down with too much code,
I'll try and post just a little information and then if that is
insufficient I can post more.

I have a C++ project that compiles fine with no warnings or errors.
It is relying on STL classes where appropriate. In one of my classes,
I needed to create a static member variable that was an STL map. By
merely adding the line #include <map>, I suddenly get a whole slew of
compile errors, all of which appear to be in the standard include
files, such as:

[carl@e236014 initcard]$ make
g++ -O2 -ansi -pedantic -Wall -c -o cryptokiclass.o cryptokiclass.cc
g++ -O2 -ansi -pedantic -Wall -c -o listener.o listener.cc
g++ -O2 -ansi -pedantic -Wall -c -o main.o main.cc
g++ -O2 -ansi -pedantic -Wall -c -o slot.o slot.cc
In file included from /usr/include/c++/3.3.3/string:53,
from /usr/include/c++/3.3.3/stdexcept:45,
from cryptokiclass.h:5,
from slot.h:7,
from slot.cc:1:
/usr/include/c++/3.3.3/bits/basic_string.h: In member function `int
std::basic_string<_CharT, _Traits, _Alloc>::compare(const
std::basic_string<_CharT, _Traits, _Alloc>&) const':
/usr/include/c++/3.3.3/bits/basic_string.h:830: error: syntax error
before `;'
token

.... etc. etc.

If I remove the #include <map> line, they all go away. Any ideas as
to what I can do to fix this?

Thank you very much for your time.

Carl Youngblood
 
J

John Harrison

I recognize that I may not be giving sufficient information with this,
but in the interest of not bogging the list down with too much code,
I'll try and post just a little information and then if that is
insufficient I can post more.

I have a C++ project that compiles fine with no warnings or errors.
It is relying on STL classes where appropriate. In one of my classes,
I needed to create a static member variable that was an STL map. By
merely adding the line #include <map>, I suddenly get a whole slew of
compile errors, all of which appear to be in the standard include
files, such as:

[carl@e236014 initcard]$ make
g++ -O2 -ansi -pedantic -Wall -c -o cryptokiclass.o cryptokiclass.cc
g++ -O2 -ansi -pedantic -Wall -c -o listener.o listener.cc
g++ -O2 -ansi -pedantic -Wall -c -o main.o main.cc
g++ -O2 -ansi -pedantic -Wall -c -o slot.o slot.cc
In file included from /usr/include/c++/3.3.3/string:53,
from /usr/include/c++/3.3.3/stdexcept:45,
from cryptokiclass.h:5,
from slot.h:7,
from slot.cc:1:
/usr/include/c++/3.3.3/bits/basic_string.h: In member function `int
std::basic_string<_CharT, _Traits, _Alloc>::compare(const
std::basic_string<_CharT, _Traits, _Alloc>&) const':
/usr/include/c++/3.3.3/bits/basic_string.h:830: error: syntax error
before `;'
token

... etc. etc.

If I remove the #include <map> line, they all go away. Any ideas as
to what I can do to fix this?

Thank you very much for your time.

Carl Youngblood

I would look to a macro that conflicts with one of the identifiers used in
the header file. Have a look at the line 830 in
/usr/include/c++/3.3.3/bits/basic_string.h and see if you can figure out
what it is. But if your line 830 is the same as my line 830 I would bet my
house on it being a macro by the name of 'min'.

john
 
C

Carl Youngblood

You probably won't believe this, but after cutting my code into pieces
trying to figure out what was wrong, I was able to fix this error by
copying and pasting the code from the two offending files to a temporary
location, deleting the files and creating identical new copies. After
that everything compiled and ran fine. And I spent half a day banging
my head against the wall on this one! Thanks for your help.

Carl
 
V

Victor Bazarov

Carl said:
You probably won't believe this, but after cutting my code into pieces
trying to figure out what was wrong, I was able to fix this error by
copying and pasting the code from the two offending files to a temporary
location, deleting the files and creating identical new copies. After
that everything compiled and ran fine. And I spent half a day banging
my head against the wall on this one! [...]

It's called "bit decay".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,474
Latest member
AntoniaDea

Latest Threads

Top