回 帖 发 新 帖 刷新版面

主题:构造函数问题

以前写类的时候构造函数都写得空,但是这个不知道怎么搞得不能空,帮我看看要怎么填。
class math{
private:
    complex ox;
    complex oy;
    complex res;
public:
    xmath(complex a,complex b)//这里构造函数,但是不知道怎么写
    {}
    ~xmath()
    {}

    complex add(complex ox,complex oy){
        res.x=ox.x+oy.x;
        res.y=ox.y+oy.y;
        return res;
    }
};
其中complex是一个复数的类,格式是X+Yi。
删掉构造函数不会出错,但是不知道这个怎么写,这样的时候提示:
E:\VC\object\oo\fushu.cpp(24) : warning C4183: 'xmath': member function definition looks like a ctor, but name does not match enclosing class
E:\VC\object\oo\fushu.cpp(25) : error C2523: 'math::~xmath' : destructor tag mismatch

回复列表 (共1个回复)

沙发

少一个参数

我来回复

您尚未登录,请登录后再回复。点此登录或注册