gpt4 book ai didi

c++ - 错误 LNK1561 : entry point must be defined- main() exists

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

我知道这个问题已在其他地方发布,我已经尝试过这些解决方案,但我收到错误 LNK1561 并且不知道问题出在哪里。该程序计算并打印用户输入的一系列数字的最大、最小、平均值和总和。如有任何问题或需要更多信息,请提问。

    #include <iostream>
#include <climits>
using namespace std;

template <class T>
T dataSet(T &sum, T &largest, T &smallest, T avg);

template <class T>
int main(){
cout << "This program calculates and prints the largest, smallest,"
<< endl << "average, and sum of a sequence of numbers the user enters." << endl;
T avg, sum, largest, smallest;
avg = dataSet(&sum, &largest, &smallest, avg);
cout << "The largest of the sequence you entered is: " << largest << endl;
cout << "The smallest of the sequence you entered is: " << smallest << endl;
cout << "The sum of the sequence you entered is: " << largest << endl;
cout << "The average of the sequence you entered is: " << avg << endl;
return 0;
}
template <class T>
T dataSet(T &sum, T &largest, T &smallest, T avg){
T num;
signed long long int max = LLONG_MIN, min = LLONG_MAX;
int count;
do{
cout << "Enter a sequence of numbers: (^Z to quit) ";
cin >> num;
if(cin.good()){
count++;
sum += num;
if(num > max)
max = num;
if(num < min)
min = num
}
else if(!cin.good()){
cout << "Error. Try Again.";
}
}while(!cin.eof());
avg = sum / count;
return avg;
}

最佳答案

main()不能是模板。你必须删除 template <class T>它之前的行,并实例化 dataSet使用特定类型,例如 double ,例如:

// No template <class T line>
int main(){
cout << "This program calculates and prints the largest, smallest,"
<< endl << "average, and sum of a sequence of numbers the user enters." << endl;
double avg, sum, largest, smallest;
avg = dataSet(sum, largest, smallest, avg);

关于c++ - 错误 LNK1561 : entry point must be defined- main() exists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17708587/

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