关于虚函数的应用,有几点不明.希望各位大大指点.
关于虚函数的使用,有几点不明...希望各位大大指点.....................................................
关于虚函数的使用,有几点不明...希望各位大大指点.......................................................
//CShape.h
#ifndef CSHAPE_H_INCLUDED
#define CSHAPE_H_INCLUDED
#include<string>
class CPoint;
class CShape
{
public:
virtual void Draw() const;
virtual double Getcircumference()const;
virtual std::string Getname();
virtual *CShape operator+(const CPoint&);
};
#endif
//CShape.cpp
#include"CShape.h"
void CShape::Draw()const{}
double CShape::Getcircumference()const{return 0;}
std::string CShape::Getname(){return std::string("Shape");};
//*CShape CShape::operator+(const CPoint&){return this;}
virtual *CShape operator+(const CPoint&);
这个函数还没有写,光声明就报错.......
\xfb\CShape.h|11|error: ISO C++ forbids declaration of 'CShape' with no type|
\xfb\CShape.h|11|error: 'CShape' declared as a 'virtual' field|
\xfb\CShape.h|11|error: expected ';' before 'operator'|
||=== 已完成构建: 3 个错误, 0 个警告 ===|
CPoint类是public CShape类的.
关于第一个错误...我现在就在写这个类的定义,怎么会这样?无语,在CShape前加class也不行..
第二个错误求大大解释..下面这样写都可以为什么我的不可以..
class B
{
public:
virtual B* clone(void);
};
[解决办法]施主,其实你可以这样写:
virtual?CShape*?operator+(const?CPoint&);
返回值是CShape *
第二个问题,你当然可以这样写,只不过字符写反了