gpt4 book ai didi

c++ - C++中引用的无效初始化

转载 作者:行者123 更新时间:2023-12-02 11:09:20 26 4
gpt4 key购买 nike

因此,我尝试进行编译,以便我可以运行第一个函数以查看其是否正常运行,但仍会出现这些错误。请帮忙!我得到了错误:

“从类型'char'的表达式对类型'Division&'的引用的无效初始化”

我还会收到“在传递参数'void Create_Corporate_File(Division&,Division&,Division&,Division&)'时的参数1”

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

const int SIZE = 12;


struct Division
{
char divName [SIZE];
double sales [4];
};

int main()
{
char Div_E;
char Div_W;
char Div_N;
char Div_S;

void Describe_Program ();
void Create_Corporate_File (Division& Div_E, Division& Div_W, Division& Div_N, Division& Div_S);
//void Display_Corporate_Sales (Div_E, Div_W, Div_N, Div_S);


Describe_Program();
Create_Corporate_File (Div_E, Div_W, Div_N, Div_S);


system ("PAUSE");
return 0;
}


void Describe_Program()
{
cout << "This program will prompt you to enter the sales amount\n";
<< "for each quarter of the North, South, West and East Division.\n";
<< "After you enter the sales amount for each quarter, the program\n";
<< "will be able to calculate the total quarterly sales for that";
<< "division";
<<endl<endl;
return;
}

void Create_Corporate_File (Division& Div_E, Division& Div_W, Division& Div_N, Division& Div_S)
{
fstream quarterly_sales;
quarterly_sales.open ("quarterly_sales.dat" ios::out|ios::binary)

For(div = 0, div < 4, div++)
{
Division temp;

if (div == 0)
temp = Div_E;
else
if (div == 1)
temp = Div_W;
else
if (div == 2)
temp = Div_N;
else
temp = Div_S;

cout << "Please enter the division: ";
cin.getline (temp.divName, SIZE);

For(sales = 0, sales < 4, sales++)
{
cout << "Please enter the sales amount for quarter " << sales + 1 <<":\n";
cin >> temp.sales [sales];
}
}

最佳答案

Div_E等的类型为char,而Create_Corporate_File()函数将类型为Division&作为参数-将类型更改为该类型。

关于c++ - C++中引用的无效初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26663129/

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