xGen xGen - 1 month ago 14
C++ Question

Error - Too many arguments to function - long argument

I took a code snippet from a live project (which works fine) and trying to debug but gives this error.

#include <iostream>
#include <stdio.h>
#include <time.h>

using namespace std;

long aaa();

int main() {
long greg_out = aaa(1160208);
printf("greg_out = %ld\n", greg_out);
return 0;
}

long aaa(date)
long date;
{
/*Code */
}


The error is that the declaration does not have parameter date while the method body has.

The working code is exactly same. long aaa is declared without parameter. then Parameter date(which is a numeric value of date) is defined in the method body. I am not good in C programming. I need to convert this small code into another language so trying to figure out the logic.

The answers below are also giving same solution- To declare date. But i am curious how does this code work? Is it C language itself. or any variant of C?

tried to run here http://cpp.sh/

Answer

You are mixing old style C declarations and C++ constructs, this is incorrect. You should put the real signature in the forward declaration and in the definition of function aaa:

#include <iostream>
#include <stdio.h>
#include <time.h>

using namespace std;

long aaa(long);

int main() {
    long greg_out = aaa(1160208);
    printf("greg_out = %ld\n", greg_out);
    return 0;
}

long aaa(long date) {
    /*Code */
}
Comments