gpt4 book ai didi

c++ - 基类构造函数错误

转载 作者:行者123 更新时间:2023-11-28 07:52:59 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
What is this weird colon-member syntax in the constructor?

我有以下基类和派生类;

class P {
int n;
public:
P( int id );
virtual int getn();
virtual int toss( int x ) = 0;
};

class RNP : public P {
int n;
public:
RNP( int id);
int toss( int x );
};

我已经为 RNP 创建了一个构造函数,但是当我编译时出现错误

player.cc:9:11: error: constructor for 'RNP' must explicitly initialize the base class 'P' which does not have a default constructor

如何在派生类中初始化基类?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com