class Info {
public:
inline void append(int i) { var1.push_back(i); }
private:
std::list<int> var1;
};
class Key {
public:
int getId() {return id};
private:
int id;
};
class Base {
public:
void& getMap() { return myMap;}
protected:
map<Key*,Info*> myMap;
};
class B {
public:
void check(bool val,map<Key*,Info*>* = NULL) {
// while processing I get key* as key1
Key* key1;
Info* info = new Info;
info->append(1000);
myMap.insert(std::pair<Key*,Info*>(key1,info));
}
};
class Derived : public Base {
public:
void func() {
// since Derived is subclass of Class Base so we access the myMap
bobject.check(true,&myMap);
}
private:
B bobject;
};
class Client {
private:
Base b_report;
public:
void client_func() {
map<Key*,Info*> myMapClient = b_report->getMap();
// will be using myMapClient;
}
};
三级以下代码的问题
- 有没有在此代码的任何问题。我们可以通过成员变量的一个指针到其他类对象的功能
- 如何清除类基地MYMAP
- 时明确的阶级基础的
请在提交之前适当地格式化您的帖子。 –
请问每个问题一个问题。 –
为什么你在地图中存储指针?如果对象不应该被其他东西所拥有,只需将对象存储在地图中,那么您不必担心清理。 – user463035818