Reputation: 1169
I have a bytebuffer class, written in c++ by myself, i can compile it and it works as it should. Now i would like to use it in a big project, but when i include it in an another header, it throws an error if i try to build it. Here is the error:
CXX out.o
In file included from /usr/include/c++/4.6/streambuf:808:0,
from /usr/include/c++/4.6/ios:44,
from /usr/include/c++/4.6/ostream:40,
from /usr/include/c++/4.6/iostream:40,
from /path/to/file/src/someheader1.h:29,
from /path/to/file/src/someheader2.h:31,
from /path/to/file/src/somesource.cpp:24:
/usr/include/c++/4.6/bits/streambuf.tcc: In member function ‘virtual std::streamsize std::basic_streambuf<_CharT, _Traits>::xsgetn(std::basic_streambuf<_CharT, _Traits>::char_type*, std::streamsize)’:
/usr/include/c++/4.6/bits/streambuf.tcc:56:38: error: expected unqualified-id before ‘(’ token
/usr/include/c++/4.6/bits/streambuf.tcc: In member function ‘virtual std::streamsize std::basic_streambuf<_CharT, _Traits>::xsputn(const char_type*, std::streamsize)’:
/usr/include/c++/4.6/bits/streambuf.tcc:90:38: error: expected unqualified-id before ‘(’ token
In file included from /usr/include/c++/4.6/istream:859:0,
from /usr/include/c++/4.6/iostream:41,
from /path/to/file/src/someheader1.h:29,
from /path/to/file/src/someheader2.h:31,
from /path/to/file/src/somesource.cpp:24:
/usr/include/c++/4.6/bits/istream.tcc: In member function ‘std::streamsize std::basic_istream<_CharT, _Traits>::readsome(std::basic_istream<_CharT, _Traits>::char_type*, std::streamsize)’:
/usr/include/c++/4.6/bits/istream.tcc:693:46: error: expected unqualified-id before ‘(’ token
make[4]: *** [out.o] Error 1
The skeleton of the header file in the project:
#ifndef _GUARD_
#define _GUARD_
#include <string>
#include <vector>
...
#include "bytebuffer.h"
namespace A {
namespace B {
using namespace std;
using namespace A::C;
class Myclass {
public:
...
virtual void save( ByteBuffer& bb ) {
}
...
} ;
}
}
#endif
The byte buffer is realy simple, it contains a vector for data, and put and get methods for different types. If i comment out the save method in the header, nothing changes, so i don't even have to declare a byte buffer, it throws the error. What could cause this?
Upvotes: 0
Views: 2206
Reputation: 98348
Look at this error:
/usr/include/c++/4.6/bits/streambuf.tcc:56:38: error: expected unqualified-id before ‘(’ token
I happen to have this (hopefully) very same file around and line 56 is:
const streamsize __len = std::min(__buf_len, __remaining);
^
col 38
I marked also the column 38, for the reader convenience.
Oh! The error talks about a (
token but in this position there is not a (
but a min
. So my guess is that some header in your project is defining a macro min
:
#define min(a, b) ((a) < (b) ? (a) : (b))
or similar.
The solution is to find this header, and remove the macro altogether (my favorite), or rename it (into MIN
?), or else move the include of that header after all the standard includes (not always easy).
As a footnote, the MS ubiquitous <windows.h>
is known for having such a macro... maybe someone copied a little?
Upvotes: 7