class Community
{
private:
char* Name;
char foundationDate[11];
Person founderPtr;
int maxMembersCount;
int membersCount;
Person* members;
static int communitiesCount;
public:
.
.
.
Person* operator+(Community&); // operator + prototype (must return array of members)
};
Person* Community::operator+(Community& other)
{
Community temp("temp","12.11.1993",other.getFounder());
Person* ptr;
for(int i = 0 ; i < this->getMembersCount() ; i++)
{
for(int j = 0 ; j < other.getMembersCount() ; j++)
{
if(strcmp(this->members[i].getEGN(),other.members[j].getEGN()) == 0)
{
temp.addMember(other.members[j]);
}
}
}
ptr = temp.getMembers();
return ptr;
}
如果我cout<< ptr[i];
在函数中可以看到一切正常,但是当我尝试时:
Community S("obshnost","12.11.2010",A);
Community R("community","11.10.2011",B);
S.addMember(C);
S.addMember(Z);
R.addMember(C);
Person* ptr = S+R;
for(int i = 0 ; i<2 ; i ++)
{
cout<<ptr[i];
}
我看到了混乱的结果......如果有人知道我应该寻找什么,我将不胜感激:)