我知道这是很常见的问题,但对我来说还是新的!什么是悬挂指针
我不明白晃来晃去的指针的概念,是谷歌搜索和编写测试方法 找到一个...我只是想知道这是一个悬挂指针吗?因为无论我发现什么样的东西都返回 的东西,在这里我正在尝试类似的东西! 谢谢!
void foo(const std::string name)
{
new_foo(name.c_str()); ///// will it be Dangling pointer?!, with comments/Answer
///// it could be if in new_foo, I store name into Global.
///// Why?! And what is safe then?
}
void new_foo(const char* name)
{
... print name or do something with name...
}
*“!将它悬摆指针,有评论/回答是” * - 不,事实并非如此。你的第一个例子中没有悬挂指针。你在那里做的是完美的,100%安全和正确。 –
我不明白你有没有*指针* *悬挂指针* ...。 –
@TheOtherGuy我的意思是,没有const char * ...携带相同的const std :: string –