Question:
c++ syntax help with function call?
?
2011-04-29 19:51:16 UTC
I keep getting a syntax error with this line:
int cmdnum = check_cmd( const &argc, const &*argv[]);
im new to c++, I programed in java a year ago but nothing since and I cant figure out why my call to the function check_cmd isn't working?

Heres everything thats relevant:
int main::check_cmd(int const &argc, char* const &argv[]){
return 0;
}


int main(int argc, char *argv[]) {

int cmdnum = check_cmd( int const &argc, char* const &*argv[]);

return 0;
}
Three answers:
CPlusPlus Guru
2011-04-29 20:25:37 UTC
The line where you call the function check_cmd has an argument list that follows declaration syntax, not call syntax. At this point, you should not (re)declare types of arguments - you have already declared them. You should only provide the arguments themselves.



Secondly, where you declare that function, you are trying to create an array of references (&argv[]). Not allowed.



You should also drop the "main::" scope qualification - neither a namespace nor a class name.



In the end, this is it:



int check_cmd(int const &argc, char* const argv[]){

return 0;

}





int main(int argc, char *argv[]) {



int cmdnum = check_cmd(argc, argv);



return 0;

}
brugger
2016-10-19 10:04:32 UTC
your use of braces { } is a large number they're meant to encompass a code block. definitions of applications belong on the outer levels, no longer interior the midst of statements(code blocks) the compiler wont understand what to make of this mess. to that end compiler errors would be so affected as to make it impossible to artwork out whats incorrect.
Moнѕιη
2011-04-29 20:25:51 UTC
when you are calling the check_cmd function pass correct arguments. You need to pass 2 pointers from main example check_cmd(*p,*s)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...