可以吗?我正在寻找与使用成员初始化列表不同的东西(因为它出现在定义中,不一定是声明)。
像
这样的东西class(args) : superclass(fn of args);
答案 0 :(得分:2)
你所要求的是没有意义的。
在C ++中,每个类都有一个构造函数 对于构造函数,声明定义参数 对于构造函数,定义定义了参数的使用方式(比如它们如何传递给基类)。
示例:
Plop.h
=============
class Point
{
public:
Point(int x,int y);
};
class MyPoint: public Point
{
public:
MyPoint(int x);
MyPoint(int x,int y);
MyPoint(double z);
};
Plop.cpp
========
Point::Point(int x,int y)
{}
MyPoint::MyPoint(int x): Point(x,x) {}
MyPoint::MyPoint(int x,int y): Point(x*2,y-x) {}
MyPoint::MyPoint(double z): Point(sin(z),cos(z)) {}
答案 1 :(得分:0)
什么禁止你使用会员功能?