A
Avi Bercovich
Hello everybody,
I;m doing my first bits of programming with C++ using the STL. After
falling in love with the map<> container I;m now getting a little
annoyed with its mate vector<>. Using vector with the built-in types
like string and int 'm fine, but I dont understand how to declare/use a
vector filled with my own classes.
I'm obviously not understanding at all how to copy C++ objects. If
somebody would be so kind as to explain what I need to do to store my
homebrew classes in a vector container I;d be very grateful.
grts,
avi
Here's and edited for brevity version of my code and the error that
MIPSpro gives me.
------
class Device {
public:
Device(string ID, string Type, int maxSpeed=0);
~Device();
// boring getX()/setX() methods cut
private:
string _ID;
string _type;
};
Device:
evice(string ID, string Type, int maxSpeed) {
_ID = ID;
_type = Type;
}
Device:
evice(const Device& device) {
_ID = device._ID;
_type = device._type;
}
class Writer {
public:
Writer();
~Writer();
void getDevices();
// boring getX()/setX() methods cut
private:
vector<Device> _devices;
};
Writer::Writer() {
cout << "Setting up writer object." << endl;
}
void Writer::getDevices() {
map<string, string> deviceInfo = _getDeviceInfo(ID);
Device *drive = new Device( ID, deviceInfo["type"],
atoi(deviceInfo["max_speed"].c_str()));
drive->setInfo( deviceInfo["vendor"], deviceInfo["model"],
deviceInfo["revision"]);
_devices.push_back(drive);
delete drive;
}
}
}
------
gandalf avi:~/doc/IMD2/cdwriter > make
CC -LANG:std Writer.cpp -c -o Writer.o -I. ../vk/ -I/usr/include
cc-1262 CC: ERROR File = /usr/include/CC/stl_construct.h, Line = 53
No instance of constructor "Device:
evice" matches the argument list.
new (__p) _T1();
^
A template was detected during header processing.
instantiation of "void std::construct(Device *)" at line 348 of
"/usr/include/CC/stl_vector.h"
instantiation of "void std::vector<Device,
std::allocator<Device>>:
ush_back()" at line 49 of
"Writer.cpp"
1 error detected in the compilation of "Writer.cpp".
*** Error code 2 (bu21)
I;m doing my first bits of programming with C++ using the STL. After
falling in love with the map<> container I;m now getting a little
annoyed with its mate vector<>. Using vector with the built-in types
like string and int 'm fine, but I dont understand how to declare/use a
vector filled with my own classes.
I'm obviously not understanding at all how to copy C++ objects. If
somebody would be so kind as to explain what I need to do to store my
homebrew classes in a vector container I;d be very grateful.
grts,
avi
Here's and edited for brevity version of my code and the error that
MIPSpro gives me.
------
class Device {
public:
Device(string ID, string Type, int maxSpeed=0);
~Device();
// boring getX()/setX() methods cut
private:
string _ID;
string _type;
};
Device:
_ID = ID;
_type = Type;
}
Device:
_ID = device._ID;
_type = device._type;
}
class Writer {
public:
Writer();
~Writer();
void getDevices();
// boring getX()/setX() methods cut
private:
vector<Device> _devices;
};
Writer::Writer() {
cout << "Setting up writer object." << endl;
}
void Writer::getDevices() {
map<string, string> deviceInfo = _getDeviceInfo(ID);
Device *drive = new Device( ID, deviceInfo["type"],
atoi(deviceInfo["max_speed"].c_str()));
drive->setInfo( deviceInfo["vendor"], deviceInfo["model"],
deviceInfo["revision"]);
_devices.push_back(drive);
delete drive;
}
}
}
------
gandalf avi:~/doc/IMD2/cdwriter > make
CC -LANG:std Writer.cpp -c -o Writer.o -I. ../vk/ -I/usr/include
cc-1262 CC: ERROR File = /usr/include/CC/stl_construct.h, Line = 53
No instance of constructor "Device:
new (__p) _T1();
^
A template was detected during header processing.
instantiation of "void std::construct(Device *)" at line 348 of
"/usr/include/CC/stl_vector.h"
instantiation of "void std::vector<Device,
std::allocator<Device>>:
"Writer.cpp"
1 error detected in the compilation of "Writer.cpp".
*** Error code 2 (bu21)