Rückkehr Klasse pointer von einer Funktion

Ich bin nicht sicher was ist falsch mit diesem (halten Sie im Verstand ich bin irgendwie sorta neu in C++)

Habe ich diese Klasse:

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;
}

Zur compile-Zeit, diese kompiliert einwandfrei. Aber im Lauf der Zeit wirft er eine exception zur Laufzeit(eine Art access violation)

Was mache ich falsch?

  • , Der code kann möglicherweise nicht kompilieren. Ihnen fehlt das Schlüsselwort class Foo.
InformationsquelleAutor theKing | 2009-04-21
Schreibe einen Kommentar