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,并將其變為保護的
};