0

例如,如何在 C++/CLI 中创建指向数据成员的指针

ref class team
{
  List<teamMember^> members;
  teamMember^ leader;     //the aim is to make it a pointer to an element in the list
  void changeLeader(teamMember^% member)  //member is an element from members
  {
    leader=member;  //doesn't reference and %member gave an error
  }
};
4

1 回答 1

1

在 C++/Cli中,句柄 (^)类似于本机指针。此代码将起作用。

ref class teamMember
{
  public bool isLeader;
};

ref class team
{
  List<teamMember^> members;
  teamMember^ leader;     
  void changeLeader(teamMember^ member)  
  {
    if(leader != nullptr)
      leader.isLeader = false;
    leader = member;
    leader.isLeader = false;  
  }
};

看看这个这个以获取更多信息。

于 2011-11-01T18:53:43.880 回答