avatar
C*y
1
Got error C2664: 'foo' : cannot convert parameter 1 from 'B *' to 'A *&'
How can I handle it? Thanks!
class A
{
};
class B: public A
{
};
void foo( A*& a )
{
}
void bar( B*& b )
{
foo(b);
}
int main()
{
B* b = NULL;
bar( b);
return 0;
}
avatar
s*s
2
有没有哪位牛人愿意提供CV模板啊,一般多少页为好,是不是也不能太长。。?
avatar
C*y
3
I can't change the type of argument
avatar
c*g
4
ft
cv也要模板啊

【在 s**********s 的大作中提到】
: 有没有哪位牛人愿意提供CV模板啊,一般多少页为好,是不是也不能太长。。?
avatar
r*t
5
can you change the function body of foo/bar? ptr is not class obj, having no
polymorphism.

【在 C***y 的大作中提到】
: I can't change the type of argument
avatar
f*n
6
You can't. B*& is not compatible with A*&, similar to how B** is not
compatible with A**. If you could, you could do terrible things in foo()
like assign an A* to the variable that's supposed to be B*.
Maybe if you made a reference to const it would be okay, but I'm not sure about this (don't remember exactly).
avatar
b*i
7
改成
class A{
public:
int a;
A():a(0){};
};
class B: public A{
};
void foo( A*& a ){
a->a=1;
}
void bar( B*& b ){
foo((A*&)b);
}
int main(){
B* b = new B();
bar( b);
cout<a);
return 0;
}

【在 C***y 的大作中提到】
: Got error C2664: 'foo' : cannot convert parameter 1 from 'B *' to 'A *&'
: How can I handle it? Thanks!
: class A
: {
: };
: class B: public A
: {
: };
: void foo( A*& a )
: {

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。