我想知道" 虚拟基类 "是什么以及它意味着什么.
让我举个例子:
class Foo
{
public:
void DoSomething() { /* ... */ }
};
class Bar : public virtual Foo
{
public:
void DoSpecific() { /* ... */ }
};
Run Code Online (Sandbox Code Playgroud) 当"虚拟"在"Foo类:公共虚拟栏"中而不是"虚拟空白frob()"时,它意味着什么?
对于给定的方法,有8个案例源于以下三个位置存在或不存在虚拟.
我想我理解数字1和3如何相互作用,但数字2似乎是多余的.是吗?我不明白的是什么?
根据下图,我编写了我的代码.

这是我写的代码:
#include<iostream>
#include<string>
using namespace std;
class person
{
private:
int code;
string name;
public:
void setCode(int c) { code=c; }
int getCode() { return code; }
void setName(string s) { name=s; }
string getName() { return name; }
};
class account : public person
{
private:
double pay;
public:
void setPay(double p) { pay=p; }
double getPay() { return pay; }
};
class admin : public person
{
private:
string experience;
public:
void setExper(string e) { experience=e; } …Run Code Online (Sandbox Code Playgroud)