0

以下は、私が現在作業しているコードの抜粋です (残りは私の問題とは関係ありません。情報の結合情報 (情報 a1) メンバー関数に問題があります。スコープで宣言されていないというエラーが表示されます。すべて私がやりたいのは、情報を組み合わせて新しい変数を設定することです.構造体を使用してこれを成功させることができ、今ではクラスを自己学習しています.

#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;
}
4

2 に答える 2

1

コードで多くのコンパイル エラーが発生しますが、最も奇妙な部分は次のとおりです。

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

    cout << "The combined Information is: " << endl;
    info.printinformation();
//  ^^^^
//  You didn't declare info
于 2013-03-13T00:09:39.247 に答える
0

あなたが持っている:

a2.:combineInfo(a1);

そのはず:

a2.combineInfo(a1);

誤って余分な「:」があります。

于 2013-03-13T00:08:19.243 に答える