S
Shawn
Hi,
Suppose I have following classes:
class Person {
....
}
class Team {
//how to have a member variable which holds an array of objects of Person?
....
}
Person person1= new Person("John Smith");
Person person2= new Person("Linda King");
Person person3= new Person("Ed Johnson");
//here is what I want:
Team BestTeam;
BestTeam = person1 + person2;
//now an object of class Team was created and this team has the two people
BestTeam = BestTeam + person3;
//now Ed Johnson joined the team
BestTeam = BestTeam - person3;
//now Ed Johnson left the team
Can we overload "+" and "-" to achieve the effect above? If not(which is
my feeling), how can we achieve something similar? If we use a method
(say,join(), left()), please give me full implementation of the method?
Thank you very much. I greatly appreciate it.
Suppose I have following classes:
class Person {
....
}
class Team {
//how to have a member variable which holds an array of objects of Person?
....
}
Person person1= new Person("John Smith");
Person person2= new Person("Linda King");
Person person3= new Person("Ed Johnson");
//here is what I want:
Team BestTeam;
BestTeam = person1 + person2;
//now an object of class Team was created and this team has the two people
BestTeam = BestTeam + person3;
//now Ed Johnson joined the team
BestTeam = BestTeam - person3;
//now Ed Johnson left the team
Can we overload "+" and "-" to achieve the effect above? If not(which is
my feeling), how can we achieve something similar? If we use a method
(say,join(), left()), please give me full implementation of the method?
Thank you very much. I greatly appreciate it.