简体   繁体   中英

C++ nesting function with pointer as return value

I have a class containing a pointer

template<Foo> class Class{
    Foo * ptr;
public:
    //constructors, assignment
    Foo* view(){return ptr;}
}

and function taking Foo* as an argument

double fn(Foo*){ /*Implementation*/ }

Does the implementation

Class C;
fn(C.view());

cause the class member ptr to bee copied?

Yes, the pointer is passed by value, ie it's copied. Maybe twice, depending on optimizations. What it points to is not copied.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM