Ok, donc je suis un débutant en codage en C++ et je faisais ce programme de recherche de nombres premiers lorsque je suis tombé sur cette erreur. Ce n'est peut-être pas le meilleur et je suis ouvert aux commentaires. Le code ci-dessous est dans l'ordre correct et continu.Erreur C2660: la fonction ne prend pas 2 arguments C++
#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;
}
C'est donc là, il me donne une erreur
calc_primes(maxValue,primes);
Il me dit que la fonction ne prend pas de deux arguments. Cependant, la déclaration indique clairement qu'elle a besoin d'un long long int non signé et d'un vecteur de long long non signé, donc je ne suis pas très sûr.
//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;
}
Ceci est la déclaration de fonction. Pensez-vous que j'ai fait une erreur en mettant & nombres premiers?
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;
}
}
}
}
merci! Je suis vraiment un débutant XD – TheRealOrange
Vous êtes les bienvenus, heureux d'aider. –