错误 C2660:函数不带 2 个参数 C++

Error C2660: function does not take 2 arguments C++

好吧,我是 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;
        }

所以这就是它给我一个错误的地方

        calc_primes(maxValue,primes);

它告诉我该函数不带两个参数。不过声明里明明说需要一个unsigned long long int和一个unsigned long long int的vector,所以我不是很确定。

        //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;
}

这是函数声明。你认为我把 &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;
            }
        }
    }
}

可能是这个原因。 这里:

vector<int> calc_primes(const int max);

你用一个参数声明它

在这里你用 2 个参数声明它:

void calc_primes(unsigned long long int max, vector<unsigned long long int> &primes)

你的函数声明:

vector<int> calc_primes(const int max);

不符合你的功能定义:

void calc_primes(unsigned long long int max, vector<unsigned long long int> &primes)

这些应该相同才能达到预期的效果。