我想创建一个类来将辅助数据存储在任意对象中-这样做的干净方法是什么?
class A{
std::string _name;
int _val;
void * _extraData;
//I want to implement these methods
void setExtraData(void * data){
//
}
void * getExtraData(){
}
};
class B{
std::vector<A *> v;
void foo(){
//use A here - _extraData will
//be a (say) a vector<int>
}
};