I have this method declaration in Util.h file
30:string to_string(const bit_vector& v);
Util.cc file has the definition
string to_string(const bit_vec开发者_JAVA百科tor& v){
string str = "";
for (bit_vector::const_iterator i = v.begin(); i < v.end(); ++i){
if(*i == 1) str += "1";
else str += "0";
}
return str;
}
when I try to build the project it says that in line 30
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2143: syntax error : missing ',' before '&'
Im using visual studio 2008, Can some one help me to get out of these two errors! Dont know whether there is a problem with bit_vector !!! any ideas???
Visual Studio 2008 doesn't define bit_vector by default.
In the header file it has the following:
#if _HAS_TRADITIONAL_STL
typedef _Bvector bit_vector;
#define __vector__ vector
#endif /* _HAS_TRADITIONAL_STL */
But _HAS_TRADITIONAL_STL doesn't seemed to be defined by default.
Its definition of _Bvector is:
typedef vector<bool, allocator<bool> > _Bvector;
So you can either #define _HAS_TRADITIONAL_STL before including <vector> or just use vector<bool, allocator<bool>> directly.
It seems bit_vector
is not defined. There are claims that it should be included in <vector>
, but that doesn't seem to be the case on Visual Studio 2008. Try
typedef vector<bool> bit_vector;
before the first usage of bit_vector
.
From the error message it seems like when uitl.h
is being processed by the compiler it has no idea what a bit_vector
is.
You'll need to make sure that whatever header declares bit_vector
is included before that point. You can either include the header for bit_vector
in util.h
or you can add an appropriate forward declaration:
class bit_vector;
I'd also look at lines before it. The compiler clearly isn't considering bit_vector to be a type in this declaration, so yes the problem could be in the bit_vector declaration.
May be compiler does not know what is string. Write
using std::string;
bit_vector isn't part of the C++ standard library. It's part of some older non-standard STL implementations though...
SGI's STL documentation of bit_vector says:
Warning: The name bit_vector will be removed in a future release of the STL...not defined in the C++ standard, and is retained only for backward compatibility.
And the only thing on MSDN is a forum post by on of the VC++ developers:
bit_vector is not an official part of the C++ Standard and hence is not part of the Visual C++ release.
I certainly wouldn't use #define _HAS_TRADITIONAL_STL
- it's undocumented and may well disappear in future versions of the Microsoft compiler.
精彩评论