std::map error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef struct
{
int v;
string name;
}AuxInfo;
typedef struct
{
int v;
string name;
vector<AuxInfo> aInfos;
} MainInfo;
struct Compare
{
bool operator() (const string &s1, const string& s2)
{
if(s1.compare(s2) > 0)
return true;
else
return false;
}
};
typedef std::map<string, MainInfo, Compare> MyMap;
class A
{
public:
A()
{
mMyMap.clear();
}
~A(){}
void function();
MyMap mMyMap;
};
void A::function()
{
MainInfo tmpMainInfo;
tmpMainInfo.name = "vivek";
tmpMainInfo.v = 100;
AuxInfo a;
a.name = "Kumar";
a.v = 200;
tmpMainInfo.aInfos.push_back(a);
mMyMap["Name1"] = tmpMainInfo;
}
int main()
{
A a;
a.function();
return 0;
}
|
Last edited on
Wait. MainInfo is a bare bones struct. How are lines 30 and 53 compiling?
Why are you typdefing unnamed structs? That seems an odd way to avoid giving the struct a name...
Topic archived. No new replies allowed.