-2

関数からポインターアドレスを更新する方法を理解するのを手伝ってくれませんか?

C++ プロジェクトで C ライブラリ (libmpdclient) を使用しています。

C ライブラリから:

const struct mpd_song *     mpd_entity_get_song (const struct mpd_entity *entity)

私のヘッダープロトタイプ:

typedef struct {
  struct mpd_song * m_song; // from a C library
  ....                      // not important stuff
}
void GetSongInfo(const struct mpd_song * m_song, char* uri);

私のコード:

void MpdPlayer::GetSongInfo(const struct mpd_song * song, char* uri)
{
  struct mpd_entity * entity;
  mpd_send_list_meta(m_connection, *uri);
  song = mpd_entity_get_song(entity);
  mpd_entity_free(entity);

  printf("song adress: %p\n", song); // OK the result is 0x370e6e0
  printf("song duration: %u\n", mpd_song_get_duration(song)); // OK I can get the time
}

GetSongInfo(myStruct->m_song, m_fileuri);
printf("myStruct->m_song adress : %p\n", si->m_song); // FAIL the result is : nil

私は多くのことを試しましたが、私は迷っていると思います:/

4

1 に答える 1

0
struct mpd_song * MpdPlayer::GetSongInfo(char* uri)
{
  struct mpd_entity * entity;
  mpd_send_list_meta(m_connection, *uri);
  struct mpd_song * song = mpd_entity_get_song(entity);
  mpd_entity_free(entity);

  printf("song adress: %p\n", song);
  printf("song duration: %u\n", mpd_song_get_duration(song));

  return song;
}

myStruct->m_song = GetSongInfo(m_fileuri);
于 2013-06-12T10:34:54.083 に答える