首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

抽象类中是否可以进行把本抽象类作为形参引用解决方法

2012-02-13 
抽象类中是否可以进行把本抽象类作为形参引用classA{public:A()~A()virtualinttestfunc()0intoperator

抽象类中是否可以进行把本抽象类作为形参引用
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的。

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

热点排行