Passing argv
I am having difficulty passing argv using a custom class and then using the .size() function on it.
I am declaring the relevant function as follows within the class header file.
1 2 3
|
class.h
void useArgv(char**);
|
and then I am using as follows.
1 2 3 4 5
|
class.cpp
void customClass::useArgv(char* argv[]){
cout << argv.size() << endl;
}
|
and in main . . .
1 2 3 4 5 6 7
|
main.cpp
int main(int argc, char *argv[]){
. . .
customclass.useArgv(argv);
exit(0);
}
|
I get an error as follows.
1 2 3
|
class.cpp:4: error: request for member ‘size’ in ‘argv’, which is of non-class type ‘char**’
|
I do not understand why I am able to pass argv in this way but not use the .size() function on it.
You can't call size() on a pointer. argc contains the number of arguments so pass that to the function to use instead.
Last edited on
Yes, I figured that out RIGHT after I posted this. I left the post in case someone else had overlooked the same thing. Thanks.
Topic archived. No new replies allowed.