我是 C++ 的初学者。我目前正在从事一个涉及多个类的项目。我有一个关于这个问题,我有2类A和B,class B有2种方法send和registerrecievehandler其A类用途。我不明白什么时候应该继承它。我的思考过程是因为它是一个函数调用,我应该只制作class Bas的方法static吗?我不认为所以我需要创建一个类型的类对象,B因为它只是一个函数调用。
我的问题是应该class A继承class B吗?
class A{
//member variables of this class
public:
senddata(string data){
send(data)
}
createdata(){
// does something here
senddata(data); //just an example
}
receive(){
registerrecievehandler(f);
}
}
class B{ //networking stack
func_ptr* p
//other members of this class
public:
//many member functions here
send(string data){
//do something
}
registerrecievehandler(f){
p =f;
}
}
Run Code Online (Sandbox Code Playgroud)