开发者

Passing an object to a function taking pointer as parameter

开发者 https://www.devze.com 2023-01-19 11:32 出处:网络
How does it work when I only have an object but my function takes 开发者_开发技巧a pointer to that type of object.

How does it work when I only have an object but my function takes 开发者_开发技巧a pointer to that type of object.

Someoclass test1;

SomeFunction( Someclass*)
{
    //does something
};


You pass the address of the object.

SomeFunction(&test1);


To call the function, you need to use the address of operator (&). So in your case:

Someclass test1;

SomeFunction(&test1);

If you are asking how pointers work, there's a detailed explanation here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号