C+++;类实现motor

来源:百度知道 编辑:UC知道 时间:2024/05/26 03:04:22
#include<iostream>
using namespace std;
class v
{
protected:
int m,w;
public:
void run(){cout<<"run is open";}
void stop(){cout<<"stop is open";}
v(int m1=0,int w1=0){m=m1,w=w1;
};
class b:virtual public v
{
protected:
int h;
public:
b();
};
class m:virtual public v
{
int s;
public:
m();

};
class motor:public m,public b
{
public:
motor()
{

cout<<m;
}
};
void main()
{
class v e;
class b pp;
class m pp1;
class motor yy;
}
这个程序说moto类不能访问m不是都设成了虚基类了吗?问题出在哪》怎么改??

#include<iostream>
using namespace std;
class v
{
protected:
int m,w;
public:
void run(){cout<<"run is open";}
void stop(){cout<<"stop is open";}
v(int m1=0,int w1=0){m=m1,w=w1;}
};
class b:virtual public v
{
protected:
int h;
public:
b(){};
};
class M:virtual public v
{
int s;
public:
M(){};//构造函数+‘{}’

};
class motor:public M,public b
{
public:
motor()
{
cout<<m;
}
};
void main()
{
class v e;
class b pp;
class M pp1;
class motor yy;
}

你那个类的m与成员变量m都混了,编译器都不知道哪个是那个了!!!!
其变了不要其的见名知意,有意义才行!!而其不要类名与变量名都混在一起!

class v后面少个花括号
cout<<无法识别你定义的类,除非你重载操作符<<
类还能继承为虚类吗?
竟然没报错 奇怪了