简体   繁体   English

错误C2660:函数没有2个参数C ++

[英]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.

相关问题 C ++错误C2660:函数没有3个参数 - C++ Error C2660: Function does not take 3 arguments 奇怪的错误c2660“函数不带1个参数” - Strange error c2660 “function does not take 1 arguments” 错误C2660:&#39;Aba :: f&#39;:函数未使用0个参数 - error C2660: 'Aba::f' : function does not take 0 arguments 错误C2660:&#39;MouseListener :: MousePressed&#39;:函数未采用4个参数 - error C2660: 'MouseListener::MousePressed' : function does not take 4 arguments C ++中的特征库给出错误C2660:&#39;Eigen :: MatrixBase <Derived> :: eigenvalues&#39;:函数不带2个参数 - eigen library in C++ gives error C2660: 'Eigen::MatrixBase<Derived>::eigenvalues' : function does not take 2 arguments 简短版本:错误14错误C2660:“ Player :: addSpell”:函数未采用1个参数 - Short version: Error 14 error C2660: 'Player::addSpell' : function does not take 1 arguments 错误 C2660: 'std::allocator<char> ::allocate': function 不占用 2 arguments</char> - error C2660: 'std::allocator<char>::allocate': function does not take 2 arguments 错误 C2660: 'std::pair<a,b> ::pair': function 不带 2 arguments</a,b> - error C2660: 'std::pair<a,b>::pair': function does not take 2 arguments 如何解决“C2660 &#39;SWidget::Construct&#39;:函数不接受 1 个参数”? - How to resolve "C2660 'SWidget::Construct': function does not take 1 arguments"? 尝试在 windows 10 上安装 node-ffi 会出现错误:error C2660: 'v8::FunctionTemplate::GetFunction': function does not take 0 arguments - trying to install node-ffi on windows 10 gives error: error C2660: 'v8::FunctionTemplate::GetFunction': function does not take 0 arguments
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM