我正在使用TDM-GCC-64通过JetBrains CLion编译我的项目,但每当我编译代码时,我都会收到错误
C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/bits/stl_bvector.h:137:25: error: expected template-name before '<' token : public std::iterator<std::random_access_iterator_tag, bool>
似乎告诉我stl_bvector.h中存在错误。这是编译器的stl实现的问题,还是我缺少的东西?我似乎无法在StackOverflow或其他任何地方找到任何相关内容 - 所有结果都是关于人们试图编写自己的迭代器,而答案似乎对我没有任何帮助。
我的相关代码如下 的 DataStream.h
#include <bits/stl_bvector.h>
#include "Binary.h"
#include "Datum.h"
using std::size_t;
/*
Allows for the insertion of data into a compatible object.
*/
class DataStream
{
friend class Datum;
friend class Data;
unsigned char* data = nullptr;
size_t length = 1;
bool firstAvailable = true;
Binary* link = nullptr;
public:
DataStream();
explicit DataStream(Binary *);
DataStream(DataStream const&);
~DataStream();
DataStream& operator<<(bool);
DataStream& operator<<(char);
DataStream& operator<<(const char*);
DataStream& operator<<(wchar_t);
DataStream& operator<<(unsigned char);
DataStream& operator<<(short int);
DataStream& operator<<(unsigned short int);
DataStream& operator<<(int);
DataStream& operator<<(long int);
DataStream& operator<<(long long int);
DataStream& operator<<(unsigned int);
DataStream& operator<<(unsigned long int);
DataStream& operator<<(unsigned long long int);
DataStream& operator<<(float);
DataStream& operator<<(double);
DataStream& operator<<(long double);
DataStream& operator<<(Datum);
DataStream& operator<<(std::vector<bool>);
DataStream& operator<<(std::vector<char>);
DataStream& operator<<(std::vector<wchar_t>);
DataStream& operator<<(std::vector<unsigned char>);
DataStream& operator<<(std::vector<short int>);
DataStream& operator<<(std::vector<unsigned short int>);
DataStream& operator<<(std::vector<int>);
DataStream& operator<<(std::vector<long int>);
DataStream& operator<<(std::vector<long long int>);
DataStream& operator<<(std::vector<unsigned int>);
DataStream& operator<<(std::vector<unsigned long int>);
DataStream& operator<<(std::vector<unsigned long long int>);
DataStream& operator<<(std::vector<float>);
DataStream& operator<<(std::vector<double>);
DataStream& operator<<(std::vector<long double>);
//DataStream& operator<<(std::vector<Datum>); //<-- I assumed the problem originated here, since it's the only time I use a vector with a class I wrote. However, since commenting it out, nothing has changed.
void attach(Binary *);
private:
void changeLength(size_t);
template <class StreamType>
DataStream& stdStreamIn(StreamType x) {
size_t plen;
if (firstAvailable) {
if (sizeof(x) - 1 > 1) changeLength(sizeof(x));
plen = length - 1;
firstAvailable = false;
} else {
plen = length;
changeLength(length + sizeof(x));
}
unsigned char* carr = reinterpret_cast<unsigned char*>(&x);
auto c = new unsigned char[sizeof(x)];
for (size_t i = 0, ii = sizeof(x); i < ii; i++)
{
c[ii - i - 1] = carr[i];
}
for (size_t i = 0, ii = sizeof(x); i < ii; i++)
{
data[plen + i] = c[i];
if (link) link->receive(c[i]);
}
return *this;
}
template <class StreamType>
DataStream& realStreamIn(StreamType x) {
auto plen = length;
if (firstAvailable) {
if (sizeof(x) - 1 > 1) changeLength(sizeof(x));
} else {
changeLength(length + sizeof(x));
}
unsigned char* c = reinterpret_cast<unsigned char*>(&x);
for (size_t i = 0, ii = sizeof(x); i < ii; i++)
{
data[plen + i] = c[sizeof(x) - i - 1];
if (link) link->receive(c[sizeof(x) - i - 1]);
}
return *this;
}
template <class Array, class StreamType>
DataStream& stdArrStreamIn(Array x, std::size_t len) {
for (unsigned int i = 0; i < len; i++)
{
stdStreamIn<StreamType>(x[i]);
}
return *this;
}
template <class Array, class StreamType>
DataStream& realArrStreamIn(Array x, size_t len) {
for (unsigned int i = 0; i < len; i++)
{
realStreamIn<StreamType>(x[i]);
}
return *this;
}
};
DataStream.cpp
#include "DataStream.h"
#include <string.h>
DataStream::DataStream() {
data = new unsigned char[1];
}
DataStream::DataStream(Binary *datum) {
data = new unsigned char[1];
link = datum;
}
DataStream::DataStream(DataStream const &ds) {
this->data = new unsigned char[ds.length];
if (ds.length > 0) {
for (int i = 0; i < ds.length; ++i) {
this->data[i] = ds.data[i];
}
}
if (ds.link) this->link = ds.link;
}
DataStream::~DataStream() {
if (data) delete[] data;
}
DataStream &DataStream::operator<<(bool x) {
return stdStreamIn(x);
}
DataStream &DataStream::operator<<(char x) {
return stdStreamIn(x);
}
DataStream &DataStream::operator<<(const char *x) {
return stdArrStreamIn<const char *, char>(x, strlen(x));
}
DataStream &DataStream::operator<<(wchar_t x) {
return stdStreamIn(x);
}
DataStream &DataStream::operator<<(unsigned char x) {
return stdStreamIn(x);
}
DataStream &DataStream::operator<<(short int x) {
return stdStreamIn(x);
}
DataStream &DataStream::operator<<(unsigned short int x) {
return stdStreamIn(x);
}
DataStream &DataStream::operator<<(int x) {
return stdStreamIn(x);
}
DataStream &DataStream::operator<<(long int x) {
return stdStreamIn(x);
}
DataStream &DataStream::operator<<(long long int x) {
return stdStreamIn(x);
}
DataStream &DataStream::operator<<(unsigned int x) {
return stdStreamIn(x);
}
DataStream &DataStream::operator<<(unsigned long int x) {
return stdStreamIn(x);
}
DataStream &DataStream::operator<<(unsigned long long int x) {
return stdStreamIn(x);
}
DataStream &DataStream::operator<<(float x) {
return realStreamIn(x);
}
DataStream &DataStream::operator<<(double x) {
return realStreamIn(x);
}
DataStream &DataStream::operator<<(long double x) {
return realStreamIn(x);
}
DataStream &DataStream::operator<<(Datum x) {
std::vector<unsigned char> vec;
for (size_t i = 0, ii = x.size(); i < ii; i++) {
vec.push_back(x.getByte(i).raw());
}
return stdArrStreamIn<std::vector<unsigned char>, unsigned char>(vec, vec.size());
}
DataStream &DataStream::operator<<(std::vector<bool> x) {
return stdArrStreamIn<std::vector<bool>, bool>(x, x.size());
}
DataStream &DataStream::operator<<(std::vector<char> x) {
return stdArrStreamIn<std::vector<char>, char>(x, x.size());
}
DataStream &DataStream::operator<<(std::vector<wchar_t> x) {
return stdArrStreamIn<std::vector<wchar_t>, wchar_t>(x, x.size());
}
DataStream &DataStream::operator<<(std::vector<unsigned char> x) {
return stdArrStreamIn<std::vector<unsigned char>, unsigned char>(x, x.size());
}
DataStream &DataStream::operator<<(std::vector<short int> x) {
return stdArrStreamIn<std::vector<short int>, short int>(x, x.size());
}
DataStream &DataStream::operator<<(std::vector<unsigned short int> x) {
return stdArrStreamIn<std::vector<unsigned short int>, unsigned short int>(x, x.size());
}
DataStream &DataStream::operator<<(std::vector<int> x) {
return stdArrStreamIn<std::vector<int>, int>(x, x.size());
}
DataStream &DataStream::operator<<(std::vector<long int> x) {
return stdArrStreamIn<std::vector<long int>, long int>(x, x.size());
}
DataStream &DataStream::operator<<(std::vector<long long int> x) {
return stdArrStreamIn<std::vector<long long int>, long long int>(x, x.size());
}
DataStream &DataStream::operator<<(std::vector<unsigned int> x) {
return stdArrStreamIn<std::vector<unsigned int>, unsigned int>(x, x.size());
}
DataStream &DataStream::operator<<(std::vector<unsigned long int> x) {
return stdArrStreamIn<std::vector<unsigned long int>, unsigned long int>(x, x.size());
}
DataStream &DataStream::operator<<(std::vector<unsigned long long int> x) {
return stdArrStreamIn<std::vector<unsigned long long int>, unsigned long long int>(x, x.size());
}
DataStream &DataStream::operator<<(std::vector<float> x) {
return realArrStreamIn<std::vector<float>, float>(x, x.size());
}
DataStream &DataStream::operator<<(std::vector<double> x) {
return realArrStreamIn<std::vector<double>, double>(x, x.size());
}
DataStream &DataStream::operator<<(std::vector<long double> x) {
return realArrStreamIn<std::vector<long double>, long double>(x, x.size());
}
//DataStream &DataStream::operator<<(std::vector<Datum> x) {
// std::vector<unsigned char> vec;
// for (size_t i = 0, ii = x.size(); i < ii; i++) {
// for (unsigned int j = 0, jj = x[i].size(); j < jj; j++) {
// vec.push_back(x[i].getByte(j).raw());
// }
// }
// return stdArrStreamIn<std::vector<unsigned char>, unsigned char>(vec, vec.size());
//}
void DataStream::changeLength(size_t newLength) {
auto tmp = new char[length];
for (unsigned int i = 0; i < length; i++) {
tmp[i] = data[i];
}
delete[] data;
data = new unsigned char[newLength];
if (newLength >= length) {
for (unsigned int i = 0; i < length; i++) {
data[i] = tmp[i];
}
}
else {
for (unsigned int i = 0; i < newLength; i++) {
data[i] = tmp[i];
}
}
delete[] tmp;
length = newLength;
}
void DataStream::attach(Binary *data) {
link = data;
}
我为大量的代码道歉,但我真的不知道问题的根源,只是它是其中一个文件的一部分,基于编译器告诉我的内容。
非常感谢任何帮助。