-1
Class C {
 struct Something {
   string s;
   // Junk.
 }
 // map from some string to something.
 map<string, Something> map;

 // Some more code:
 const Something *Lookup(string k) const {
   const something *l = SomeLookUpFunction();
   cout << l;
   cout << &l->s;
   cout << l->s;
   return l;
  }
}

// Some Test file
const C::Something *cs = C::Lookup("some_key");
cout << cs;
cout << &cs->s;
cout << cs->s;

奇妙なことに、この出力は次のとおりです。
* 検索機能の場合:
0x9999999
0x1277777
some_string

* テスト コードの場合
0x9999999
0x1277777
00000000000000000000000000000000000000 ....

テスト ファイルでは非常に長いゼロの文字列が返されますが、アドレスは同じです。何がうまくいかないのでしょうか?

4

1 に答える 1