[英]Error C2660: function does not take 2 arguments C++
Okay so I'm a beginner at coding in C++ and I was making this prime number finding program when I stumbled across this error. 好的,所以我是C ++编码的初学者,当我偶然发现此错误时,我正在开发此素数查找程序。 This may not be the best and i am open to feedback. 这可能不是最好的,我愿意接受反馈。 The code below is in correct order and continuous. 下面的代码是正确的顺序,并且是连续的。
#include "stdafx.h"
using namespace std;
//finds prime numbers using Sieve of Eratosthenes algorithm
vector<int> calc_primes(const int max);
int main()
{
unsigned long long int minValue;
unsigned long long int maxValue;
bool Loop = true;
char chContinue;
vector<unsigned long long int> primes;
std::string Path;
Path = "D:\\Work\\Documents\\prime.txt";
// TODO: code your application's behavior here.
while (Loop == true)
{
cout << "Enter minimum prime number checking range (__________)" << endl ;
cin >> minValue;
cout << "Enter maximum prime number checking range (__________)" << endl ;
cin >> maxValue;
if (maxValue <= minValue)
{
cout << "Invalid selection" << endl <<endl <<endl <<endl ;
continue;
}
So this is where it gives me an error 所以这是给我一个错误的地方
calc_primes(maxValue,primes);
It tells me that the function doesn't not take two arguments. 它告诉我该函数没有两个参数。 However, the declaration clearly states that it needs a unsigned long long int and a vector of unsigned long long int, so I'm not very sure. 但是,该声明明确指出它需要一个unsigned long long int和一个unsigned long long int的向量,所以我不太确定。
//opens file path
std::ofstream of;
of.open(Path);
//writes to file and displays numbers
for(unsigned long long int i = 0; i < primes.size(); i++)
{
if(primes.at(i) != 0)
{
cout << primes.at(i) <<" ";
of << primes.at(i) << " ";
}
}
cout << endl <<endl <<endl <<endl ;
of.close();
cout << "Continue? (y/n)" << endl ;
cin >> chContinue;
if (chContinue == 'y') {
continue;
}
else
{
if (chContinue == 'n')
{
break;
}
else
{
cout << "Invalid Selection" << endl << endl ;
}
}
}
return 0;
}
this is the function declaration. 这是函数声明。 Do you think I've made a mistake by putting &primes? 您是否认为我在输入“&primes”时犯了一个错误?
void calc_primes(unsigned long long int max, vector<unsigned long long int> &primes)
{
// fill vector with candidates
for(unsigned long long int i = 2; i < max; i++)
{
primes.push_back(i);
}
// for each value in the vector...
for(unsigned long long int i = 0; i < primes.size(); i++)
{
//get the value
unsigned long long int v = primes[i];
if (v != 0)
{
//remove all multiples of the value
unsigned long long int x = i + v;
while(x < primes.size())
{
primes[x] = 0;
x = x + v;
}
}
}
}
Might be this is the reason. 可能这就是原因。 Here: 这里:
vector<int> calc_primes(const int max);
you declaring it with one parameter 你用一个参数声明
And here you declaring it with 2 parameters : 在这里,您使用2个参数声明它:
void calc_primes(unsigned long long int max, vector<unsigned long long int> &primes)
Your function declaration : 您的函数声明 :
vector<int> calc_primes(const int max);
doesn't match your function definition : 与您的函数定义不匹配:
void calc_primes(unsigned long long int max, vector<unsigned long long int> &primes)
These should be identical to achieve desired results. 这些应该相同以获得期望的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.