Another thing to consider:
This is plain procedural code, using only an ISO C library, in files called *.c, and you STILL write C++, using e.g. the std::string class for nothing else than accessing the char* inside.
Try writing real C instead, use C++ for projects that actually USE its features. Reasons to do so:
- portability
- no symbol mangling (binary compatibility with libs)
- not confusing others who may work on the code later
- not carrying unneeded stuff in the final binary
I'm NOT AT ALL advocating against C++ here, I just hate to see C-code in C++
Oh and: Don't do implementation in header files. In your example.h file, just give the prototype like
Code:
int whatever(char *foo, int baz);
implement it in example.c, and put both, main.c and example.c in your gcc commandline.