I have a class with private strings and after I set information I want to the given strings in that class I need to push that data to a vector, which is stored privately in a separate class...I feel as though my code makes logical sense but obviously I am missing a step as it pushes back blank data...a summery of the code is here

class person{
private:
string name;
string age;
string location;

public:

//general gets and sets are coded here, etc..

};



class people{
private:
vector<person> pplgroup;

public:

void pushbackppl(Person Guy){

pplgroup.push_back(Guy);

}

};


void storeinfo(){

person Guy;
people Everyone;


Guy.setAge("Twenty");
Guy.setName("John");
Guy.setLocation("USA");

Everyone.pushbackppl(Guy);

}

Is my method of pushbackppl wrong to do? I am very confused as to what is going on as the vector inside class Everyone is pushing back as it should, but not the data, just emptiness.

Recommended Answers

All 6 Replies

Where is storeinfo defined? (in other words what is it a method of)

storeinfo does not belong to any class, it is called from a main, does that cause a problem?

If the code's not too unwieldy please post the whole thing so I can test it out.

actually its about 8 pages so it might be a hassle, alot more is going on but everything else seems to do its job as planned, its just the vector is pushing back nothing...

everything else seems to do its job as planned

Well, something is happening somewhere that's what makes it difficult to discern. Fleshing out the code a little bit to get something that compiles I was able to print out what had been push_back'ed. You have "Person" on line 22 instead of "person" but I suspect it's more from your paraphrasing than an error in the code.

yes sorry i actually noticed that i wrote it in caps and in lower case in two parts but thats an error in my forum post, not in the actual code, either way I'll probably just try to do something totally different with the structure of the program that creates the same result as I cant see what is wrong

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.