Hello, wondering if anyone can help me. Using CodeBlocks 12.11. I've been trying to write a program using wxWidgets and finally gave up because... well, it was much less fun than I imagined. (Never "GUIed" before - yep, just coined that) I gave up and tried to rewrite it the old fashioned way. I started with a basic skeleton and cannot get it to compile which is making me wonder if I've screwed up my configurations someplace. (I hate to muck with the configurations too much because my wxWidgets code is finally compiling after many agonizing attempts.) Do I have to have completely different configurations if I want to leave out the interface? The other possibility is that I've completely lost it, and hours of tyring to "GUI" has made my brain gooey... ;) that was so cheezy it made me blush... Any comments will be greatly appreciated, at my expense or otherwise. :) Okay to the point...
Can somebody tell me if there is a major error in my code or suggest a solution? Here we go...
How then can I create a library of functions where I don't have to declare an object first? It seems I've done that in other programs and I'm wondering what the difference is. My intention was to create a library and not really an object and I seem to have really confused myself. Can I nix the creator and destructor? I used the class wizard to create the class.
Note that I moved the line #include <iostream> from the .cpp file to the .h file which is a better place for it. In addition I added endl to the cout statement to flush the buffer and move the cursor down to the next line. You can add additional functions to FnLib using the same technique, a forward declaration in the header file and the implementation of the function in the code file.
You can also eliminate the line #include <iostream> in Main.cpp since you have already included it in FnLib.h, though it doesn't hurt anything to have it there since there will be header guards in <iostream> to prevent double inclusion.
Note that I moved the line #include <iostream> from the .cpp file to the .h file which is a better place for it.
I completely disagree with the end of this statement. There is nothing in the FnLib.h header that requires anything declared in iostream. By including iostream in this header file, every file that includes FnLib.h will include iostream also. In more sophisticated programs, this can lead to unnecessary dependencies and unnecessarily long rebuild times. While the effect is trivial in this toy program, this strategy would not be considered good programming practice.
A header file should include only headers that it needs to define its classes and declare its functions. A header file should never include extraneous header files -- the fewer included files the better. In this case, the iostream header file should be included in FnLib.cpp as originally proposed, because that's the file that uses items defined in iostream.
You can also eliminate the line #include <iostream> in Main.cpp since you have already included it in FnLib.h
I agree that iostream should not be included in Main.cpp, but not for the reason stated. The iostream header should be removed from Main.cpp because nothing in Main.cpp requires anything from iostream.