我不知道什麼是錯的這個(記住我有點八九不離十新的C++)返回類指針
我有這個類:
Foo
{
string name;
public:
SetName(string);
}
string Foo::SetName(string name)
{
this->name = name;
return this->name;
};
//////////////////////////////////////////////
//This is where I am trying to return a Foo pointer from this global function:
Foo * ReturnFooPointer()
{
Foo foo;
Foo * foo_ptr;
foo_ptr = &foo;
return foo_ptr;
}
在編譯時,這個編譯得很好。然而在運行時,它會拋出運行時異常(某種訪問衝突)
我在做什麼錯?
該代碼無法編譯。您錯過了Foo上的類關鍵字。 – 2009-04-21 19:42:34