- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我有一些课
class A {
...
};
里面封装了一些变量和方法。我的问题是,如果类有可能“学习”新方法 - 某些函数正在将新方法放入类主体中。
比如我有一个空类
class Draw {};
我程序中的一些函数从文件中读取数据并基于这些可以绘制圆形、方形等。是否可以将这些绘制方法放在 Draw 类主体中,以便它动态增长?
最佳答案
是的。
class Draw
{
public:
ReturnType call(const std::string& methodName, ArgTypes args)
{
return methods[methodName](this, args);
}
private:
std::unordered_map<
std::string,
std::function<ReturnType(Draw*, ArgTypes)>
> methods;
};
根据需要添加到方法
。
(我已经抽象掉了 ReturnType
和 ArgTypes
;在那里选择你需要的。)
关于c++ - 通过添加新方法来发展类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29966098/
如果有人能为我分解它,让我能理解它,我会非常感激。我知道它用于通过 apply 方法创建新对象。 Function.prototype.new = function () { var args
新版本的HADOOP中有一个方法。http://hadoop.apache.org/docs/current/api/org/apache/hadoop/fs/FileSystem.html#conc
根据支持库变更日志和 Fragment 类文档 ( https://developer.android.com/reference/android/support/v4/app/Fragment.ht
根据支持库更改日志和 Fragment 类文档 (https://developer.android.com/reference/android/support/v4/app/Fragment.htm
执行Async BigJob() 的无限运行任务的正确方法是什么?并且可以根据要求停止 提示:我正在尝试学习 [一种] 新方法来更新我现有的策略。 我有一个简单的程序(测试程序),它有一个开始 和停止
我将解释我的想法:我使用 python 作为谷歌应用程序引擎 + js + css 主项目将存储在 src 文件夹下,如下所示:\src \app <--- 这里是 gae 的所有 python 应用
我是一名优秀的程序员,十分优秀!