C++中有三种常见的继承方式:公有继承、私有继承和保护继承。
class Base {
public:
int publicMember;
protected:
int protectedMember;
private:
int privateMember;
};
class Derived : public Base {
// Derived继承了Base的publicMember和protectedMember
};
class Derived : private Base {
// Derived继承了Base的publicMember和protectedMember,并将其变为私有的
};
class Derived : protected Base {
// Derived继承了Base的publicMember和protectedMember,并将其变为保护的
};