Mar 13, 2012 at 2:58am UTC
I'm probably doing this wrong, I don't typically use vectors and I am starting to jump on the band wagon but I have no idea how to pass them by reference this is what I tried doing but I am getting a illegal use of this type of expression error. Any ideas would be great as I am lost thanks
void ques3(int *narow,int *right,int *wrong){
srand(time(0));
int pullnames=5;
vector<string> ques3namelist;
vector<string> ques3namespulled;
quesnames(*narow,vector<string> &ques3namelist,vector<string> &ques3namespulled);
}
//I also tried quesnames(*narow,&ques3namelist, &ques3namespulled);
Last edited on Mar 13, 2012 at 3:00am UTC
Mar 13, 2012 at 2:59am UTC
If you want to pass it as a reference, just give the name like you are passing by value normally.
Mar 13, 2012 at 3:01am UTC
Do you mean just &ques3namelist? Because for some reason that wasn't working either
Mar 13, 2012 at 3:25am UTC
No, just the name of the variable, like you are passing by value.
Mar 13, 2012 at 3:42am UTC
That doesn't seem to work because when I try to access an element it doesn't print anything
void ques3(int *narow,int *right,int *wrong){
srand(time(0));
vector<string> q3namespulled(*narow);
int rando=14;
int chk=0;
quesnames(*narow, q3namespulled);
cout<<q3namespulled[1];
}
is what i tried I hate to ask do I need to ask the element in a different way?
Mar 13, 2012 at 4:01am UTC
What does quesnames() do?
Mar 13, 2012 at 4:07am UTC
creates a list of random names
using
string names[] = {"Tina","Aaron","Alan","Christi","Edgar","Marie","Sophia","Dale","Frank","Bruce","Marilyn","Joe","Alice","Natalia","Paul", "Katherine", "Simon", "Nick","Chris","Josh","Jeremy", "Nisa", "Marlon","Will","Eliza","Kat","Raj","Howard","Amy","Penny"};
vector<string> nameslist(names, names+29);
pullednames.resize(nameslong);
//I use a for loop with a while loop nested inside to pull the random names
Mar 13, 2012 at 4:12am UTC
Im pretty sure Arrays and Vectors are passed by reference normally. I know that Arrays are just Pointers to char, so a vector couldnt be *too* different. Correct me if im wrong
Mar 13, 2012 at 4:14am UTC
Vectors are actually different, and are passed by value unless you specify otherwise.
@TC: What does the function definition look like? Do you modify the vector reference you are taking?
Mar 13, 2012 at 4:14am UTC
Wow never mind I made a STUPID mistake but thank you for your help