我是C++的新手,我遇到了一个我不明白的错误.
class1* a = (class1*)p1;
class2* b = (class2*)p2;
a->foo(b);
Run Code Online (Sandbox Code Playgroud)
错误是:
error: no matching function for call to 'a::foo(b*&)'
note: candidates are: void a::foo(const b&)
Run Code Online (Sandbox Code Playgroud)
我怎么做到这一点?
par*_*mar 10
你可能不得不这样做
a->foo(*b);
Run Code Online (Sandbox Code Playgroud)
因为foo引用b而不是指向b的指针.
C++中指针变量和引用变量之间有什么区别?是学习C++中指针和引用之间差异的好地方