读书人

抽象类中是否可以进行把本抽象类作为形

发布时间: 2012-02-13 17:20:26 作者: rapoo

抽象类中是否可以进行把本抽象类作为形参引用
class A{
public:
A();
~A();
virtual int testfunc()=0;
int operator <(A a);
};
编译出错:
cannot declare parameter `a ' to be of type `A ' because the following virtual functions are abstract

[解决办法]
int operator <(const A & a) const;

[解决办法]
引用参数
[解决办法]
int operator <(const A & a) const;
[解决办法]
virtual int testfunc() const =0;
作为一个 <比较,它应该是严格的const的。

[解决办法]
虚函数,自己不能调啊
[解决办法]
要用的话要用引用或指针。否则就成了递归定义

读书人网 >C++

热点推荐