错误C2660:函数不接受2个参数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; }

错误C2660:函数不接受2个参数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; },c++,function,primes,C++,Function,Primes,它告诉我函数不接受两个参数。然而,声明明确指出它需要一个无符号long-long-int和一个无符号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 < prim

它告诉我函数不接受两个参数。然而,声明明确指出它需要一个无符号long-long-int和一个无符号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;
}
//打开文件路径
std::的流;
开放(路径);
//写入文件并显示数字
for(无符号长整型i=0;i可能这就是原因。
在这里:

向量计算素数(const int max);
您可以使用一个参数声明它

在这里,您使用两个参数声明它:

void calc_primes(unsigned long long int max, vector<unsigned long long int> &primes)
void计算素数(无符号长整型最大值、向量和素数)

可能是因为这个原因。
在这里:

向量计算素数(const int max);
您可以使用一个参数声明它

在这里,您使用两个参数声明它:

void calc_primes(unsigned long long int max, vector<unsigned long long int> &primes)
void计算素数(无符号长整型最大值、向量和素数)
您的函数声明:

向量计算素数(const int max);
与您的函数定义不匹配:

void计算素数(无符号长整型最大值、向量和素数)
为了达到预期的效果,这些函数应该是相同的。

您的函数声明:

向量计算素数(const int max);
与您的函数定义不匹配:

void计算素数(无符号长整型最大值、向量和素数)

这些应该是相同的,以达到预期的结果。

你的答案很有帮助,因为我在脑海中看到了你的答案,我没有声明重载函数,声明后,它工作了。@shoaibsabir太棒了!你的答案很有帮助,因为我在脑海中看到了你的答案,我没有声明重载函数,声明后,它工作了。@shoaibsabir!你的答案很有帮助太棒了!
vector<int> calc_primes(const int max);
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)