gpt4 book ai didi

c++成员函数声明问题w/class

转载 作者:行者123 更新时间:2023-11-28 07:43:25 25 4
gpt4 key购买 nike

下面是我目前正在使用的代码的摘录(其余部分与我的问题无关。我在使用 Information combineInfo(information a1) 成员函数时遇到问题。我得到一个错误,它没有在范围。我想做的就是合并信息并设置新变量。我能够使用结构成功地做到这一点,现在我正在自学类(class)。

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

最佳答案

你的代码有很多编译错误,但最奇怪的部分在这里:

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

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

关于c++成员函数声明问题w/class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15374635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com