Hi there,
i work on a linux platform and was able to handle arguments in standard c programs in the past.
I am actually a bit frustrated about getting passing arguments to a c++ structured program to run, and I need to say I am not an expert in c++ right now.
I did already consulate my c++ books, but they pay no attention to arguments then I goggled to several websites including this forum, there where a lot hints but I was not able to point out my pitfall...
http://www.cplusplus.com/forum/beginner/26251/
http://www.crasseux.com/books/ctutorial/argc-and-argv.html
I think I have trouble with the right prototypes on the right place.
I actually found no way to get it to compile without errors... :-(
Only when I remark the argument lines and use (void) instead of (int argc, char *argv[])it compiles fine.
I think I need some help here now...
The Program structure is the reduced one of the program, I use in my project, where I need to implement the arguments.
I have on all places remarked lines in the code to be able to exchange them like:
int cApp::main(void)
//int cApp::main(int argc, char *argv[])
When I use the (void) lines the code compiles fine with:
g++ arg_test.cpp -o arg_test
When I use the (int argc, char *argv[]) lines instead of (void) I have different error messages. below I did several permutations of lines commented in and out with between the recompiling, but no success..
Only the following errors
linux:/home/be/connect # g++ arg_test.cpp -o arg_test
arg_test.cpp:33: error: prototype for `int cApp::main(int, char**)' does not
match any in class `cApp'
arg_test.cpp:8: error: candidate is: int cApp::main()
linux:/home/be/connect # g++ arg_test.cpp -o arg_test
arg_test.cpp: In function `int main(int, char**)':
arg_test.cpp:45: error: no matching function for call to `cApp::main()'
arg_test.cpp:33: error: candidates are: int cApp::main(int, char**)
linux:/home/be/connect # g++ arg_test.cpp -o arg_test
arg_test.cpp:25: error: prototype for `cApp::cApp(int, char**)' does not match
any in class `cApp'
arg_test.cpp:3: error: candidates are: cApp::cApp(const cApp&)
arg_test.cpp:10: error: cApp::cApp()
arg_test.cpp: In function `int main(int, char**)':
arg_test.cpp:45: error: no matching function for call to `cApp::main()'
arg_test.cpp:33: error: candidates are: int cApp::main(int, char**)
may be someone of you can point out my pitfall?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
// Class of application
class cApp
{
public:
int Test; // just a vriable
public:
int main(void);
//int main(int argc, char *argv[]); // error
cApp(void);
// cApp(int argc, char *argv[]); //error
};
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
class cApp App;
// Constructor of applications
cApp::cApp(void)
//cApp::cApp(int argc, char *argv[]) // error
{
Test=1; // just a vriable
};
// Main Programm of Application
int cApp::main(void)
//int cApp::main(int argc, char *argv[]) // error
{
printf("Hello World :%d\n",Test);
return 0;
}
// Start of application
int main(void)
//int main(int argc, char *argv[]) // error
{
printf("Launch application\n");
App.main();
printf("goodbye\n");
return 0;
}
|