H
Hatzigiannakis Nikos
I want to use a map container with objects of the following class
rectangle. Each object will be accosiated with a key of type string:.
#include <iostream>
#include <string>
#include <map>
using namespace std;
class rectangle
{
float side_a;
float side_b;
public:
float area() {return side_a * side_b;}
rectangle(float a, float b) {side_a=a; side_b=b;}
};
map<string,rectangle> mymap;
main()
{
rectangle rec1(10,20);
//the following statment does not compile
mymap["table"] = rec1;
system("pause");
}
1. The statment mymap["trapezi"] = rec1; supposed to add a new element in
the map with the key "table" and value the object rec1 but it doesnt
compile. why?
2. If I finaly manage to add a new element how can I have access to the
mebers of the rectangle object in a map element ?
Thanks a lot
rectangle. Each object will be accosiated with a key of type string:.
#include <iostream>
#include <string>
#include <map>
using namespace std;
class rectangle
{
float side_a;
float side_b;
public:
float area() {return side_a * side_b;}
rectangle(float a, float b) {side_a=a; side_b=b;}
};
map<string,rectangle> mymap;
main()
{
rectangle rec1(10,20);
//the following statment does not compile
mymap["table"] = rec1;
system("pause");
}
1. The statment mymap["trapezi"] = rec1; supposed to add a new element in
the map with the key "table" and value the object rec1 but it doesnt
compile. why?
2. If I finaly manage to add a new element how can I have access to the
mebers of the rectangle object in a map element ?
Thanks a lot