user2163231
user2163231

Reputation:

c++ member function declaration issue w/ class

Below is an extract of the code that I am currently working with (the rest is unrelated to my issue. I am having trouble with the Information combineInfo(information a1) member function. I get an error that it's not declared in the scope. All I want to do is combine the information and set new variables. I was able to this successfully using a structure and now I am self-learning classes.

#include <iostream>
#include <string>

using namespace std;

struct Date
{
    int month;
    int day;
    int year;
};

class Information
{
public:
    Information(); 
    void printinformation(); 
    Information combineInfo(Information a1);
    //Setters and Getters Here
private:
    string a;  
    double b; 
    double c; 
    Date d;
    Date e;
};

void initializeDate(Date& d);
void printDate(Date& d);

int main()
{
    cout << endl << "Now please input Information #1" << endl;
    Information a1;  // prompts for all the inputs for a1
    cout << endl << "Now please input Information #2" << endl;
    Information a2;  // prompts for all the inputs for a2
    a2.combineInfo(a1);  // again prompts for info??
    cout << "The combined Information is: " << endl;
    info.printinformation();
    return 0;
}

Information::Information()
{
    string a;
    cout << "Please enter a"<<endl;
    getline(cin, a);
    cout <<"Please enter b?"<<endl;
    cin >> b;
    getline(cin, dummy);
    cout <<"Please enter c?"<<endl;
    cin >> c;
    getline(cin, dummy);
    cout << "Please input the info start dates."<< endl;
    initializeDate(start);
    cout << "Please input the info end dates."<< endl;
    initializeDate(finish);
}

Information Information::combineInfo(Information a1)
{
    Information a1;
    Information a2;
    Information info;
    a1.a = a2.a;
   //etc.
    return info;
}

Upvotes: 0

Views: 81

Answers (2)

Andy Prowl
Andy Prowl

Reputation: 126542

Your code gives a lot of compilation errors, but the weirdest part is here:

    Information a2;
    a2.:combineInfo(a1);
//    ^^ Remove the :

    cout << "The combined Information is: " << endl;
    info.printinformation();
//  ^^^^
//  You didn't declare info

Upvotes: 1

Jamin Grey
Jamin Grey

Reputation: 10495

You have:

a2.:combineInfo(a1);

It should be:

a2.combineInfo(a1);

There's an extra ':' in there by mistake.

Upvotes: 0

Related Questions