C
cmk128
Hi
#include <stdio.h>
#include <string>
using namespace std;
class mother{
private:
string str;
public:
mother(){
str="peter cheung";
}
string getStr(){
return str;
}
};
class child
ublic mother{
};
class child2
ublic child2{
};
void func1(mother *m){
}
int main(){
mother *m=new child2(); <------------ this will fail, but
this can, mother *m=new child()
child2 c;
printf("str=%s\n",m->getStr().c_str());
func1(&c); <------------- this will fail too
because c is from class child2, not child . java can accept parameter
of all its sub-class, whatever how depth it is inheritanced. do we have
anyway to solve it?
return 1;
}
thanks
from Peter ([email protected])
#include <stdio.h>
#include <string>
using namespace std;
class mother{
private:
string str;
public:
mother(){
str="peter cheung";
}
string getStr(){
return str;
}
};
class child
};
class child2
};
void func1(mother *m){
}
int main(){
mother *m=new child2(); <------------ this will fail, but
this can, mother *m=new child()
child2 c;
printf("str=%s\n",m->getStr().c_str());
func1(&c); <------------- this will fail too
because c is from class child2, not child . java can accept parameter
of all its sub-class, whatever how depth it is inheritanced. do we have
anyway to solve it?
return 1;
}
thanks
from Peter ([email protected])