0

I need to send the list of the input arguments to readInput function. But the compiler gives error when I call readInput function. Could you please tell me where my mistake is?

bool readInput(netcorr net,int argc, char * argv[]);

int main(int argc, char * const argv[]) {
    netcorr net;
    bool error=readInput(net, argc, argv);
}

bool readInput(netcorr &net,int argc, char * argv[])
{
}

thanks for your help. Pegah

Edit: The compiler says

Fehler: Argument 3 von »bool readInput(netcorr, int, char**)« wird initialisiert

Fehler: ungültige Umwandlung von »char* const*« in »char**«

Translation by aschepler:

Error: Argument 3 of 'bool readInput(netcorr, int, char**)' is initialized

Error: invalid conversion from 'char* const*' to 'char**'

11
  • 2
    You missed the const before argv in readInput definition Commented Mar 19, 2011 at 16:03
  • 1
    When I was in uni, I would debug C++ by throwing in *, &, and const in different places until it worked. Now I'm a Java guy. :-O Commented Mar 19, 2011 at 16:05
  • 1
    The compiler already told you what the mistake is... you should at least paste the compile error text in your question. Commented Mar 19, 2011 at 16:06
  • 1
    @glowcoder this is easy to understand 1. In variable declaration * means pointer and & means reference 2. In variable using * means dereferencing & menas address of variable Commented Mar 19, 2011 at 16:08
  • FYI: it is also usually a good idea to add the compiler error messages. Commented Mar 19, 2011 at 16:10

2 Answers 2

3

Because you try to redirect char * const[] to char*[]. Change your main function to get cahr *[] or change readInput function to get char *const[].

Sign up to request clarification or add additional context in comments.

2 Comments

@ Mihran Hovsepyan that does not work. the error is: undefined reference to `readInput(netcorr, int, char**)
@Martin in question there was no point to give answer that accepts all ISO standarts, I just give solution of his problem. Also I don't think in nowdays you can find any compiler that doesn't accept char *const[] as type of argv of main function.
1

You declared a function taking netcorr as it's first argument, and then defined one taking netcorr& as it's first argument. In addition, you tried to pass a char* const[] as a char*[].

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.