本文介绍了在C ++中返回指向本地/堆栈变量的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个functionx教程感到困惑....
<a href="http://www.functionx.com/cpp/examples/returnpointer.htm">http://www.functionx.com/cpp/examples/returnpointer.htm</a>[<a href="http://www.functionx.com/cpp/examples/returnpointer.htm" target="_blank" title="New Window">^</a>]
将返回指向myclass的本地对象的指针正确吗?该对象是否会在超出功能范围时被破坏...感到困惑....
我在msdn论坛中提出了问题...仍然不清楚...

http://social.msdn .microsoft.com/Forums/zh-CN/vclanguage/thread/75f14e6f-7e75-4d3a-abc0-b18514eed24c/?prof = required [ ^ ]

I am confused on this functionx tutorial....
<a href="http://www.functionx.com/cpp/examples/returnpointer.htm">http://www.functionx.com/cpp/examples/returnpointer.htm</a>[<a href="http://www.functionx.com/cpp/examples/returnpointer.htm" target="_blank" title="New Window">^</a>]
will returning a pointer to an local object of myclass is correct? will that object destroyed on going out of function scope... confused....
I raised the question in msdn forum... still not clear...

http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/75f14e6f-7e75-4d3a-abc0-b18514eed24c/?prof=required[^]

推荐答案


double * GetSalary()
{
    static double salary = 26.48;

    return &salary;
}


欢呼声,
AR


cheers,
AR



这篇关于在C ++中返回指向本地/堆栈变量的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 08:19