Angus Leeming <[EMAIL PROTECTED]> writes:
| QUESTION 1
| ==========
| If I have a struct NamedColor
| struct RGBColor {
| int r, g, b;
| };
| struct NamedColor : public RGBColor {
| string name;
| };
|
| and then I create a database of colors, so:
| vector<NamedColor> colorDB;
|
| then why can't I do:
| colorDB.erase();
| ?
|
| cxx bombs out with
| cxx: Error: FormPreferences.C, line 828: #304 no instance of overloaded
| function "std::vector<T, Allocator>::erase [with T=NamedColor,
| Allocator=std::allocator<NamedColor>]" matches the argument list
|
| what do I need here?
colorDB.clear();
| QUESTION 2
| ==========
| Can I "merge" two vectors of the same kind to create a new, larger vector.
| Something like:
|
| vector<NamedColor> redDB = ...'
| vector <NamedColor> orangeDB = ...;
| vector <NamedColor> colorDB = redDB + orangeDB;
sure...
vector<string> a;
vector<string> b;
vector<string> sum;
sum.insert(sum.end(), a.begin(), a.end()); // linear time
sum.insert(sum.end(), b.begin(), b.end()); // linear time
Lists are better suited for this:
list<string> a;
list<string> b;
list<string> sum;
sum.splice(sum.end(), a); // constant time
sum.splice(sum.end(), b); // constant time
Lgb