Friend Function: Combine 2 Clubs

(solved)
Last edited on
Not enough information.

You haven't shown us the declaration for Club, so we don't know how you are storing the member names.

Ideally, if you've stored them as a std::set<string>, the member names will already be in alphabetical order. Given that, there are several possible approaches:
1) Iterate through the two lists and finding where there is a member in both lists, when found in both lists, insert the name into temp's set of member names.
2) Iterate though the first list and use set::find to see if the member is in the second list.
3) Iterate through the first list and use set::equal_range to see if there is a matching entry in the second list.


Last edited on
I have added to my original post. If more is needed, please let me know. Also, I cannot use vectors in this case.
closed account (j3Rz8vqX)
Prediction: It may be going out of scope?

From what I can see:

addMember looks fine.

mergeClubs, can be iffy. temp is going to be destroyed soon.

You best copy the name of that club in the returning process.

Pointing and storing it won't apply. Copy its club name. =D
(clear)
Last edited on
You still haven't shown us club.h with the declaration of your Club class as previously requested.

Do you have a Club constructor that takes a string? I can only guess because you haven't shown us the Club declaration.

You say it prints blanks, but you haven't shown us the print code.

We're not mind readers. We can't tell you what's wrong with your code if we can't see it.
(clear)
Last edited on
You're making this really difficult by not posting what is asked for. I don't care about the larger program and never asked you to post the larger program. However, I have asked for your declaration of the Club class multiple times. You're also complaining that is not printing, but you haven't shown us your print code (which has also been asked for).

As for your merge function, you're going to need a Find function which returns true if a name is a member of a club. Given that Find function, here is what you need to do (general idea. Not intended to compile):

1
2
3
4
5
6
7
8
Club temp;
for (int i=0; i<A.numMembers; i++)
{  string a_name = A.members[i];
    if (B.Find(a_name))
    {  // member of both clubs
        temp.addMember (a_name);
    }
}





Last edited on
Thank you @AbstractionAnon and all others that responded. Your help was highly appreciated and has steered me in the appropriate direction.
Topic archived. No new replies allowed.