There seems to be 2 main problems here. The error you are getting is in how you are calling addSchool()
. You are using the syntax to call a static function when you have it declared as a member. To call it as a member:
school.addSchool(newSchool);
Note using the .
instead of ::
, but also that newSchool is already a pointer so don't take the address of it. (As others already pointed out)
The other problems are run time errors in your addSchool method. You are creating a local vector, not using the member. You are also ignoring the parameter sent.
void school::addSchool(school *s) {
for( i=0; i < s->size(); i++) {
this.schools.push_back(s[i]);
}
}
Now that I write that out, I realize there is also a bigger logical problem here in what this class actually is supposed to be. Its a school that contains a list of schools, so are you adding a school to that list or combining lists? While such things make sense for link lists and trees, your example says "schools" so I would rethink it. Perhaps your class should be a school district to contain a list of schools:
class District{
private:
vector<school *> schools; // school declared elsewhere
public:
District();
inline int Size() { return this.schools.size(); };
inline int Get(int i) { return this.schools[i]; };
void addSchool(school *s);
void addSchools(District *d);
}
// adding to the list
void District::addSchool(school *s) {
this.schools.push_back(s);
}
// adding the contents of another like class, consider operator overloading + instead
void District::addSchools(District *d) {
for( i=0; i < d->Size(); i++) {
this.schools.push_back( d->Get(i) );
}
}
Alternately, if you want a single static function as a master list, lookup the Singleton design pattern.