基于Policy的Class设计,很郁闷的编译错误

chenyu2202863 2009-10-17 08:55:03
先上关键代码


template<typename T>
struct CCYControlCreator
{
/*CCYControlT<CCYButtonT> *CreateControl()
{
return NULL;
}*/
};
template<>
struct CCYControlCreator<CCYButtonT>
{
//CCYControlT<CCYButtonT> *CreateControl()
//{
// CCYControlT<CCYButtonT> *pControl = new CCYControlT<CCYButtonT>;
// //pControl->Create();
// return pControl;
//}
};
template<>
struct CCYControlCreator<CCYIconButtonT>
{
//CCYControlT<CCYIconButtonT> *CreateControl()
//{
// CCYControlT<CCYIconButtonT> *pControl = new CCYControlT<CCYIconButtonT>;
// //pControl->Create();
// return pControl;
//}
};


template
<
typename T,
template<typename> class TCreatePolicy = CCYControlCreator
>
class CCYControlManagerT
: public TCreatePolicy<T>
{
//私有成员
private:
CCYControlT<T> *m_pControlHover; // 正在移动的控件
CCYControlT<T> *m_pControlDown; // 被鼠标按下的控件
CCYControlT<T> *m_pControlSelected; // 选中的控件

。。。。

编译不过,错误提示为
1>d:\project\windows\wtl\exercise\lokiim\lokiim\ui\control\cycontrolmanagert.h(254) : error C2977: “UI::Control::CCYControlManagerT”: 模板 参数太多
1> d:\project\windows\wtl\exercise\lokiim\lokiim\ui\control\cycontrolmanagert.h(55) : 参见“UI::Control::CCYControlManagerT”的声明

=======================================
我就纳闷了,为啥我CCYControlT也是这样的类,为啥就能编译过呢?
就是因为这个template<typename> class TCreatePolicy = CCYControlCreator。很不明白,
如果需要,我可以贴上完整的代码
...全文
120 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenyu2202863 2009-10-18
  • 打赏
  • 举报
回复
谢了,倒是可以~

我现在在研究Loki里Functor的实现,它利用Typelist,但是好麻烦~
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 chenyu2202863 的回复:]
你的意思是这样

void Func(vector <boost::any>)

?
[/Quote]
对啊,只不过效率有点低了
chenyu2202863 2009-10-18
  • 打赏
  • 举报
回复
你的意思是这样

void Func(vector<boost::any>)

?
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 chenyu2202863 的回复:]
参数数量也不同

[/Quote]
boost::any可以放任意类型的数据,vector则是不固定长度的。
chenyu2202863 2009-10-17
  • 打赏
  • 举报
回复
参数数量也不同
  • 打赏
  • 举报
回复
vector<boost::any> ?
这个应该合适
chenyu2202863 2009-10-17
  • 打赏
  • 举报
回复
我也是vc9~

发现了问题所在了,由于我CCYControlManagerT类需要使用CCYControlT类的私有成员变量,于是在CCYControlT类的头文件中对CCYControlManagerT写了前置声明!造成了类类型不统一~
汗~忙活了半天!!

请允许我再问个问题:

Loki的Typelist如何成为函数的参数进行传递,我想进行变参传递(不想用C风格的...),用其它能实现的方法也成!
  • 打赏
  • 举报
回复
我这个代码就能编译过去,莫非是你的编译器不支持?
我这里是VC9
struct CCYButtonT{};
struct CCYIconButtonT{};


template<typename T>
struct CCYControlCreator {
};
template<>
struct CCYControlCreator<CCYButtonT> {
};
template<>
struct CCYControlCreator<CCYIconButtonT> {

};

template<class T>
struct CCYControlT
{
};

template
<
typename T,
template<typename> class TCreatePolicy = CCYControlCreator
>
class CCYControlManagerT
: public TCreatePolicy<T>
{
//私有成员
private:
CCYControlT<T> *m_pControlHover; // 正在移动的控件
CCYControlT<T> *m_pControlDown; // 被鼠标按下的控件
CCYControlT<T> *m_pControlSelected; // 选中的控件
};


int main()
{
CCYControlManagerT< CCYButtonT > xx;
return 0;
}
chenyu2202863 2009-10-17
  • 打赏
  • 举报
回复
我把模板参数
template<typename> class TCreatePolicy = CCYControlCreator
替换为
typename U
后,也得到同样的错误?
难道我类里有冲突的代码?
实在不明白!

64,680

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧