类型:转载 责任编辑:asp.net 日期:2007/05/23
热门软件下载:
代码如下
#include <stdio.h>
class Tree
{
public:
virtual Tree& Subtree()
{
printf("%s\n", "Tree");
return *this;
}
};
class GeneralTree : public Tree
{
public:
GeneralTree& Subtree()
{
printf("%s\n", "GeneralTree");
return *this;
}
};
int main()
{
return 0;
}
网友回答:
DEV-C++,C_Free BCB都可以编译通过
返回值不同是不能用overridde
#include <stdio.h>
class Tree
{
public:
virtual Tree* Subtree()
{
printf("%s\n", "Tree");
return this;
}
};
class GeneralTree : public Tree
{
public:
tree* Subtree()
{
printf("%s\n", "GeneralTree");
return this;
}
};
返回值类型不同应该不算函数标识不同吧...
在继承派生关系中.若基类中某函数被声明为virtual,
而在派生类中有着相同的函数标识的函数..则将重写基类的虚函数.
我觉得楼主代码中的重写是成功的...
考虑到类型的隐式转换,返回值不能作为override的。