简体   繁体   English

C ++传递一个结构并传递一个可互换的指针?

[英]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 是struct的单个实例,将调用

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); 是struct的单个实例,将调用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 . 如果一个函数需要一个指向struct的指针,则必须给它一个指向struct的指针。 Arrays are special since they decay to a pointer to the first element. 数组之所以特别是因为数组会衰减到指向第一个元素的指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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