【发布时间】:2012-01-05 02:23:02
【问题描述】:
我在库中有这段代码:
class Parent
{
//some data and functions
};
void myfunc(Parent& ref);
我想在我的应用程序中执行此代码:
class Child : public Parent
{
// some other data and functions
void dostuff()
{
myfunc(*this);
}
};
通过 *this 是否安全? (没有切片,没有复制,......) 像这样调用 myfunc 更好吗:
myfunc( * ((Parent*)this) )
请注意,我无法控制 myfunc 内部发生的事情,在某些情况下,我什至不知道里面发生了什么。
我多次使用过指针传递,我已经习惯了,但之前从未使用过传递父引用。
【问题讨论】:
标签: c++ oop inheritance pass-by-reference