【发布时间】:2012-06-21 23:57:52
【问题描述】:
我有一个模板类,叫做Cell,这里是定义:
template <class T>
class OneCell
{
.....
}
我有一个从Cell 到 T 的转换运算符,这里
virtual operator const T() const
{
.....
}
现在我有派生类,称为DCell,在这里
template <class T>
class DCell : public Cell<T>
{
.....
}
我需要重写 Cell 的演员表操作符(插入一点 if),但之后我需要调用 Cell 的演员表操作员。在其他方法中,它应该类似于
virtual operator const T() const
{
if (...)
{
return Cell<T>::operator const T;
}
else throw ...
}
但我遇到了编译器错误
错误:“const int (Cell::)()const”类型的参数与“const int”不匹配
我能做什么?
谢谢你,对不起我的英语不好。
【问题讨论】:
-
我把整个代码都放好了,这样会更好
标签: c++ templates inheritance casting virtual