H
Hill
I want a class Table which saves one list of Pair<int,std::string>.
And I want that it has following behaviour:
Table t;//now t is empty
try{
int i = t["me"];// I want this call to an empty table will throw a
exception [case 1]
}
catch(...){
std::cout << "It's a empty table,bad operator" << std::endl;
t["me"] = 0;//and i hope this call can work well [case 2]
}
Could some one tell me how to define this class Table?
How to define operator for case 1 and case 2?
class Table
{
public:
class Bad_op{};
struct Pair
{
int data;
std::string str;
};
Table(const Table& table);
Table();
~Table();
Table& operator= (const Table& table);
//int& operator[](const std::string& str);???????
//nst int& operator[](const std::string& str)const;???????
private:
std::vector<Pair> m_Vec;
};
And I want that it has following behaviour:
Table t;//now t is empty
try{
int i = t["me"];// I want this call to an empty table will throw a
exception [case 1]
}
catch(...){
std::cout << "It's a empty table,bad operator" << std::endl;
t["me"] = 0;//and i hope this call can work well [case 2]
}
Could some one tell me how to define this class Table?
How to define operator for case 1 and case 2?
class Table
{
public:
class Bad_op{};
struct Pair
{
int data;
std::string str;
};
Table(const Table& table);
Table();
~Table();
Table& operator= (const Table& table);
//int& operator[](const std::string& str);???????
//nst int& operator[](const std::string& str)const;???????
private:
std::vector<Pair> m_Vec;
};