c++ - Confused about passing argument via custom functional object
问题描述
For now, I'm trying to make a little graphic class from custom class with two fields:
struct Prog {
Prog(int y, const string& s) :yy{ y }, name{ s }{}
Prog() :yy{0}, name{"none"} {}
int yy;
string name;
};
Then I create my functional object, to convert argument to coordinates value:
class Scale {
public:
Scale() : cbase{ 40 }, vbase{ 1960 }, scale{ 20 }{};
int operator()(const int y) {
return cbase + (y - vbase) * scale;
}
private:
int cbase;
int vbase;
double scale;
};
And this is my Graphic class:
class Prog_shape :public Shape {
public:
Prog_shape(const Prog& p) :txt{ {sc(p.yy),240},p.name }, cir{ {sc(p.yy),244},10 } { }
void draw_lines() const {
txt.draw();
cir.draw();
}
private:
Graph_lib::Text txt;
Scale sc;
Graph_lib::Circle cir;
};
And the function that is filling the Shapes container from vector<Prog>
:
void generate_figures() {
for (auto p : p_vec) {
sh_vec.push_back(new Prog_shape{ p});
}
}
And now I'm really confused about my Prog_shape
class's txt
object, I can't get the value from the Scale
func object, while the cir
object can. When I take a few moments to debug, I find values passed to the txt
constructor are 0. How can it be possible when the values must be the same?
解决方案
推荐阅读
- php - 如何在查询中添加 where between?
- python - 一起训练多个 tensorflow NN
- python - 使用 urlsplit 从 url 中获取域名
- git - 本地 Git 存储库的文件夹名称可以与存储在 Github 上的版本不同吗?
- android - 如何在 BottomSheetDialog 中为不同的状态 STATE_EXPANDED 和 STATE_COLLAPSED 设置视图?
- javascript - Javascript:可以访问返回 json 的 url 但在获取时发生错误
- python - Python闭包是否需要外部范围超出范围(即结束)
- leaflet - 修改传单库中的缩放中心?setZoomAround 有效但不是交互式的
- javascript - 将 laravel 查询与 DataTable 一起使用
- javascript - 来自对话框的 Google Apps 脚本访问值