push back on object
Hi again!
I have a question!
I have this class
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class Ziak{
private:
string Meno;
int Cislo, Rocnik;
vector<int> Kurzy;
public:
void Uprav(string NMeno, int NCislo, int NRocnik){
Meno=NMeno; Cislo=NCislo; Rocnik=NRocnik;
}
int ZistiCislo(){ return Cislo; }
int ZistiPocetKurzov(){ return Kurzy.size()-1; }
int ZistiCisloKurzu(int i){ return Kurzy[i]; }
};
| |
then in the next class this:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class Spojenie{
private:
vector<Ziak> ziak;
vector<Kurz> kurz;
public:
bool AddZiak(string Meno, int Rocnik){
int ID=0;
. . .
ziak.push_back();
ziak[ziak.size()-1].Uprav(Meno, ID, Rocnik);
return true;
}
};
| |
Here
ziak.push_back();
it is causing error cuz I dont know what I have to give there as arguments
Can someone help me please? :)
P.S.: Sorry for non-english names of variables :)
You need to push_back an instance of Ziak:
1 2
|
Ziak z;
ziak.push_back(z); // z will be copied!
| |
yeah thanks
so if it is copied I can use the copy contructor insteda of Uprav function yes?
EDIT:
I do it like this
declared constructor
1 2 3
|
Ziak(string Nmeno, int NID, int NRocnik){
Meno=Nmeno; Cislo=NID; Rocnik=NRocnik;
}
| |
and to class Spojenie add a block
1 2 3 4
|
{
Ziak z(Meno, ID, Rocnik);
ziak.push_back(z);
}
| |
Last edited on
so if it is copied I can use the copy contructor insteda of Uprav function yes? |
Yes
thanks :)
Topic archived. No new replies allowed.