我有一个字节缓冲区类,由我自己用 c++ 编写,我可以编译它并且它可以正常工作。现在我想在一个大项目中使用它,但是当我将它包含在另一个标题中时,如果我尝试构建它会引发错误。这是错误:
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
项目中头文件的骨架:
#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
字节缓冲区非常简单,它包含一个数据向量,以及不同类型的 put 和 get 方法。如果我在标头中注释掉 save 方法,没有任何变化,所以我什至不必声明字节缓冲区,它会引发错误。什么可能导致这种情况?