简体   繁体   中英

C++ passing a struct and passing a pointer interchangeable?

If the function is:

void foo(struct* bar)
{
}

And

struct foobar;

Is a single instance of struct, will the call

foo(foobar);

Be treated as if it were a pointer to a one member array? Will the call be legal or does it require an overload?

Is a single instance of struct, will the call foo(foobar); Be treated as if it were a pointer to a one member array? Will the call be legal or does it require an overload?

No, it will not. The call is not legal, and an overload could make the call work.

If a function needs a pointer to a struct , then you have to give it a pointer to a struct . Arrays are special since they decay to a pointer to the first element.

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