作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的程序是:-
#include < iostream.h>
#include < conio.h>
struct base
{
protected:
void get()
{
cin>>a>>b;
}
public:
base(int i=0, int j=0);
void put()
{
cout << a << '\t' << b << "\tput 1";
}
int a,b,c;
~base()
{
cout << "base destroyed";
}
};
class deri : protected base
{
int c,d;
char w;
int ans;
public:
deri(int r=7, int s=0)
: base(r,s)
{
c=r;
d=s;
cout << "\nDerived invoked\n";
}
void put()
{
cout << c << '\t' << d << '\t' << a << '\t' << b;
}
};
class d2 : protected deri
{
public:
d2() {}
void start();
void add()
{
get(); // ERROR HERE: Implicit conversion of 'd2 *' to 'base *' not allowed
}
~d2(){}
};
void d2::start()
{
put();
}
base::base(int i, int j)
{
a=i;
b=j;
cout << "\nbase invoked\n";
cout << "Enter a,b: ";
get();
}
void main()
{
clrscr();
getch();
}
任何人都可以解释错误消息的含义吗?
最佳答案
您可能使用的是旧编译器,因为您包含了 <iostream.h>
而不是新标准 <iostream>
而且您没有使用命名空间 std.
修复此问题后,添加行 using namespace std;
在顶部并注释掉 clrscr() 你的代码在 MSVC8 上编译得很好。
你有明确的理由使用protected
吗?偏差?如果没有,我建议使用 public
取而代之的是偏差。 protected
推导是一件非常复杂和不常见的事情。
关于c++ - 隐式转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2147077/
我是一名优秀的程序员,十分优秀!