J
John Harrison
Oliver Gebele said:/*
OK, after years i'm still more into C;
but i already do understand some C++.
And there are still many things about
the STL which i do not know...
I try to put 8-character-arrays in a vector
and when compiling on my Linux-box i get too
many errors to include here.
Can anybody tell me what my problem is?
And possibly how to fix it?
*/
Arrays are not copyable in C++. The reason you cannot put an array into a
vector is the same reason that you cannot do this
char a[8];
char b[8];
b = a; // error, arrays are not copyable
You have a couple of options (at least)
You could create a vector of vectors
vector< vector<char> > nodes;
or a vector of strings
vector< string > nodes;
but neither of these enforce the restriction you want (eight char arrays).
So probably a better option is to create an 8 character array class and use
that. Something like this
class EightCharArray
{
public:
EightCharArray();
EightCharArray(const char*);
char operator[](int i) const;
char& operator[](int i);
private:
char data[8];
};
vector< EightCharArray> nodes;
nodes.push_back("abcdefg");
I guess you can fill in the details of this class (and add some more) but
ask again if you need to.
john