Sign in to follow this  
scheols

Class Member Function Definition inclusion question

Recommended Posts

scheols    100
Ok, I'm reading "C++ in Plain English" By Brian Overland and I think its missing a whole section or something is wrong with his example. Basically heres all the files i typed in from the example: http://www.uni-code.com/C-C++/book%20example/ What I'm confused about is the class member function definition isn't included in the main file so how would the class run properly? Would I have to include the "cstr.cpp" file in the main.cpp file to work properly? Thats the only way I'm seeing this working. Am I correct or is there something I should know about Classes this book isn't telling me.

Share this post


Link to post
Share on other sites
Scet    960
The class is defined in cstr.h, I really don't see what the problem is here. Definitions go in headers and code goes in source files, that's how it works with C and C++.

I would suggest though that you throw your book in the garbage. Any book with "C++" in the title that uses C-style strings is crap. Plus he used the unsafe C functions instead of the ones meant to prevent buffer overflows. I could write a better book.

[Edited by - Scet on July 8, 2007 6:47:45 PM]

Share this post


Link to post
Share on other sites
Antheus    2409
Doesn't the book explain the pre-processing, compilation, link process?

Might as well read through a recently published tutorial, which explains, among other things, the build process as well.

And I agree, that the examples presented have little to do with C++. They are just the usual C with classes. For a C++ book, the only string manipulation demonstrated should be with std::string.

Long story short:
- Compiler pre-processes and compiles all the .cpp files.
- When a .cpp file #includes another file, the contents of that file are inserted into the cpp file.
- End result of this are object files, compiled code
- Linker than connects these into an executable, and connects the symbols

Share this post


Link to post
Share on other sites
scheols    100
Quote:

Doesn't the book explain the pre-processing, compilation, link process?


Naw it really doesn't, thanks i'll check out that tutorial now.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this