I have an array teams[size]
.
Team* relatedTeam
I know that the relatedTeam
above is member of a teams
. So, this is pointer. How can i find its index from this information?
I am in transition from java to c++.
I am looking for a method like:
int pos = teams.indexOf(relatedTeam);
Sorry, I might not explained it well because of my poor Enghlish.
Team* relatedTeam = findTeam("fenerbahce");
and findTeam method
Team* SocReg::findTeam(string teamName)
{
for (int i = 0; i < size; i++)
{
if (stricmp(teams[i].getName, teamName.c_str) == 0)
return &teams[i];
}
return NULL;
}
I know that team is returned without NULL from this method. So I just need its index
我想我明白了
int index = relatedTeam - teams;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.