在C++中将类对象作为参数传递

Ste*_*eve 4 c++ arguments class

假设我有一个名为foo的类,主要包含用于显示数据的数据和类栏.因此,如果我有foo的对象实例名为foobar,我将如何将其传递到bar :: display()?像空栏::显示(foobar和测试)?

Jim*_*som 9

是的,差不多.或者,如果可能,使用const引用来表示该方法不会修改作为参数传递的对象.

class A;

class B
{
    // ...
    void some_method(const A& obj)
    {
        obj.do_something();
    }
    // ...
};
Run Code Online (Sandbox Code Playgroud)