c++ - 如何使类函数自动处理不同的变量
问题描述
我有几何课。
class Geometry
{
private:
float width;
float height;
bool isVisible;
public:
float getWidth();
void setWidth(float value);
float getHeight();
void setHeight(float value);
bool getIsVisible();
void setIsVisible(bool value);
};
该应用程序有一个接收传入消息的服务器,例如
Geomery*Width 5;
此消息告诉应用程序将几何对象的宽度设置为 5
所以我有另一个班级可以做到这一点
class CommandInterface
{
void ProcessCommand( std::string command , std::shared_ptr<Geometry> Geom)
{
std::vector<std::string> cmd;
// split the commandReceived and fill the vector
if (cmd[1] == "Width")
{
Geom->setwidth(atof(cmd[2]));
}
// Other if conditions for other values
}
};
我可以使 CommandInterface 自动化吗?
目前,如果我向几何类添加一个新的数据变量,我需要向 ProcessCommand 函数添加另一个 if 条件。
解决方案
推荐阅读
- javascript - 如何对来自 Node 的 MaxListenersExceededWarning 消息进行故障排除?
- python - 如何在 Python 中循环遍历 3D NIFTI 图像
- mysql - 试图连接 asp.net 和 mysql 试图找出 mysql.data.dll
- angular - Angular 7 Material DatePicker 无法使用 DRF 格式化
- reactjs - 使用 React 获取 csrftoken cookie
- c# - C#~如何读取MultiLevelPointer?
- c# - 如何从 Xamarin.IOS UIImage 获取像素数据?
- c# - Dispatcher.Invoke 是否在内部调用 CheckAccess?
- python - 我可以使用 plotly 仅绘制 3D 坐标吗?
- macos - 如何在 Mac OS 上使用 Qt Designer 设置 Qwt 6.1.3?