我有类Signal和Image,并且这两个类都具有名称相同但输入和输出参数不同的方法。它允许吗?派生类的方法从基类调用方法
template <class T> class Signal {
Signal<T> zeroPadding(Signal<T>);
}
template <class T> class Image:public Signal<T>
{
public:
Image(void);
~Image(void);
Image(int,int);
Image(int,int,double);
Image(int,int,double,double);
Image<T> zeroPadding(Image<T>);
template <class T> Image<T>::Image(int width,int height):Signal(width,height) {}
template <class T> Image<T>::Image(int width,int height,double dt):Signal(width,height,dt) {}
template <class T> Image<T>::Image(int width,int height,double dt,double t0):Signal(width,height,dt,t0) {}
template <class T> Image<T> Image<T>::zeroPadding(Image<T> im2){
Image<T> i1 =(*this);
Image<T> i2 =im2;
if (i1.getHeight()==im2.getHeight()){
i2.zeroPadding(i1); /* I want to call zeroPadding function from class Signal<T>. How I can convert i1 and i2 to class Signal<T> without initialization?*/
}
}
你可以修复你的格式,使其可读? – Chad
通过限定名称:'i2.Signal :: zeroPadding(i1);'限定名称告诉在哪里查找函数。 'i1'会自动通过[slicing]转换成'Shape'(http://stackoverflow.com/questions/274626/what-is-the-slicing-problem-in-c)。你的代码很奇怪,至少可以说。你为什么要在函数中复制'this'? –
jrok
我相信你可以'static_cast&>(i2).zeroPadding(i1);'也。请参阅:http://ideone.com/ej1C1T –
Chad