在这个程序中,我们使用从 a 类到 c 类的数据转换。当我们使用
a(c c1)
{
return (c1.getd()*100)
}
// constructor in class a, this is correct, but when when we use
c(a a1)
{
return (a1.getb()/100)
}
// constructor, then compile error comming that getb is not a member of a please clear what is the problem.
#include<iostream.h>
#include<conio.h>
class a;
class c {
int d;
public:
c() {
d=0;
}
c(int x) {
d=x;
}
int getd() {
return d;
}
void putdata() {
cout<<d;
}
c(a a1){
d=(a1.getb()/100);//here is compile error coming --getb is not a member of a
}
};
class a {
int b;
public:
a() {
b=0;
}
a(int x) {
b=x;
}
void putdata() {
cout<<b;
}
int getb() {
return b;
}
};
void main() {
c c1;
a a1=100;
a a2(100);
c1=a1;
c1.putdata();
getch();
}