gpt4 book ai didi

c++ - 无法将参数 1 从 'Class *' 转换为 'double []'

转载 作者:行者123 更新时间:2023-11-30 04:27:17 24 4
gpt4 key购买 nike

<分区>

好吧,这是我拿到这里但无法编译的 C++ 代码

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

const int n = 900;
class City{
string name;
double area;
int count, roads;


public:
City() {}
City(string a, double b, int c, int d ) { a=name; b=area; c=count; d=roads;}
string getname() {return name;}
double getarea() {return area;}
int getcount() {return count;}
int getroads() {return roads;}
friend ostream& operator << (ostream& , City& );
friend istream& operator >> (istream& , City& );

};

ostream& operator << (ostream& out, City& a) {
out<<"name "<<a.name<<", area "<<a.area<<", count "<<a.count<< ", roads "<<a.roads<<endl;
return out;
}
istream& operator >> (istream& in, City& a) {
in>>a.name>>a.area>>a.count>>a.roads;
return in;
}
void fill(int arr[], int size){
ifstream ifs("cities.txt.");
for (int i=0;i<size;i++)
ifs>>arr[i];
}


void func(City* arr){
ofstream ofs("density.out");
for(int i=0;i<n;i++){
if(arr[i].getcount()/arr[i].getarea()>1000)
ofs<<arr[i];
}
}

int main(){
City* hm;
hm = new City[n];
fill(hm, n);
func(hm);
system ("pause");
return 0;
}

这是我在编译时遇到的错误:

error C2664: 'fill' : cannot convert parameter 1 from 'City *' to 'int []'

我以某种方式看到,它说类“City *”和 int[] 数组有问题,但无法弄清楚。我用双倍但相同的概率更改了“int”。那是个问题,否则它似乎是一个来自文件的简单数组填充函数。知道它有什么问题吗?

那么,会怎样

void fill(City& arr, int size) 's body would like?

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