简体   繁体   English

C ++错误:'int'之前的预期primary-expression

[英]C++ error: expected primary-expression before ‘int’

I am getting this error for every int in this section of code; 我在这部分代码中的每个int都收到此错误;

if(choice==2) {
    inssort(int *a, int numLines);
}
if(choice==3) {
    bubblesort(int *a, int numLines);
}
if(choice==4) {
    mergesort(int *a, int numLines);
}
if(choice==5) {
    radixsort(int *a, int numLines);
}
if(choice==6) {
    return 0;
}

Thats where I call the functions in main. 这就是我在main中调用函数的地方。 If you are wondering I am writing a small program that gives the user a choice when sorting a list between 4 different types of sorting algorithms. 如果您想知道我正在编写一个小程序,在用户在4种不同类型的排序算法之间排序列表时可以选择。

Any help would be appreciated. 任何帮助,将不胜感激。

You can't use the declaration types when you're calling the functions. 调用函数时,不能使用声明类型。 Only when you declare them are they needed: 只有在你声明它们时才需要它们:

if(choice==2)
{
    inssort(a, numLines);
}
if(choice==3)
{
    bubblesort(a, numLines);
}
if(choice==4) 
{
    mergesort(a, numLines);
}
if(choice==5) 
{
    radixsort(a, numLines);
}
if(choice==6) 
{
    return 0;
}

You're using function declaration syntax to make function calls . 您正在使用函数声明语法来进行函数调用 That's not necessary, and (as you have discovered) doesn't even work. 这没有必要,而且(正如你所发现的那样)甚至都不起作用。 You can just write 你可以写

if (choice == 2)
    inssort(a, numLines);
// etc

By the way, a switch would be more idiomatic here. 顺便说一下,这里的switch更加惯用。

if(choice==2)
{
 inssort(int *a, int numLines);
}

your code turn to this 你的代码转向此

if(choice==2)
{
 inssort(&a, numLines);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM