开发者

How to do casting map?

 template <class S>
 struct C {
     S* operator()(void* c) { return (S*)c; }
 };

Idea is that I can do:

C<QRadioButton> caster;
void* p = ??;
caster(p)->width();

where p is a pointer to a QRadioButton开发者_开发百科, but kept as a void*.

What I'd like to do is keep a map of caster objects, e.g.

map<std::string, ??> Caster;

Caster["radio"]    = C<QRadioButton>;
Caster["checkbox"] = C<QCheckBox>;

So that I could do:

Caster["radio"](p)->width();

Any idea how to set this up?


I am not too sure, but it looks like you want to use Boost.Any

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜