0

I've been at this code for the past few hours and cant seem to wrap my head around what the error could be. I've created the member functions and I'm sure they're being called correctly in main. Before every variable being used as an argument for the class functions being called in main, the error message is "Error: expected primary expression before 'variable'".

class Name_pairs
{    
    public:

    Name_pairs();

    void read_names(string nameOfPerson, vector <string> names);
    void read_ages(vector <double> ages, double ageOfPerson, vector <string>& names);
    void print();

 private:

    string nameOfPerson;
    double ageOfPerson;
    vector <string> names;
    vector <double> ages;
};`

Name_pairs::Name_pairs()
{

}

Name_pairs::read_names(nameOfPerson, names)
{
while(true)
{
    cout << "Please enter a name: (enter q to end) " << endl;
    cin >> nameOfPerson;

    if(nameOfPerson == q)
    {
        names.push_back(nameOfPerson);
        break;
    }else{
        names.push_back(nameOfPerson);
    }
 }

}

Name_pairs::read_ages(ages,ageOfPerson, names)
{
    int z =0;
    while(true)
    {
            cout << "Please enter " << names[a] << "'s age: "
            cin >> ageOfPerson;

            ages.push_back(ageOfPerson);
            z++;

            if(ages.size()== names.size() )
            {
                break;
            }
    }
}


And then where the problem occurs is in the main function.

int main()
{
Name_pairs identifier;
identifier.read_names(string nameOfPerson, vector <string> names);
identifier.read_ages(vector <double> ages, double ageOfPerson, vector <string> names);


return 0;

}

Any help will be appreciated

Aquasylum
  • 59
  • 3
  • 10
  • 1
    These functions are being defined and used completely wrong. You may be sure they are being called correctly, but then you are mistaken. Really, the best thing would be to find a good [book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – chris Aug 10 '14 at 19:55
  • The error message should include a line number. Indicate, with a comment in your source, which line it refers to, at least for the first error. – Keith Thompson Aug 10 '14 at 20:03

1 Answers1

0

There are numerous errors in your code. Most obvious ones are that the return type and argument types are missing in the definition of Name_pairs::read_names:

void Name_pairs::read_names(string nameOfPerson, vector <string> names) {
  // ... 
}

and the parameters should probably be passed by reference as correctly noticed by @Neil Kirk.

Same for read_ages.

Also you shouldn't specify types in the calls to these methods:

string nameOfPerson;
vector <string> names;
identifier.read_names(nameOfPerson, names);
vitaut
  • 49,672
  • 25
  • 199
  • 336
  • 2
    The parameters should probably be passed by reference. – Neil Kirk Aug 10 '14 at 20:00
  • Ok I've fixed the above mentioned errors but now when I call the functions in main it states that the variables have not been declared (vector names , etc). I have the header file of the class included in main. – Aquasylum Aug 11 '14 at 05:42