Sams Teach Yourself in 24 hours.....
I don't think I like the flow of this book. I was reading a CHAPTER on pointers and it went along describing and explaining it. The next chapter was about references. And it was more less saying that using pointers can lead to memory leaks and that it is not a good idea to use pointers. Another thing, it teaches the goto() fucntions and THEN tells you not to ever use it. Things like these are what I think makes this book a poor read. I think I should just cough up the money and get the Sams Teach Yourself in 21 Days. I don't think I like Liberty's books but I haven't tried any others. I have read some reviews though. Seeing as he wrote,"Teach yourself C++ in 20 minutes" just goes to show....:p .
A question:
If pointers are such a bad thing then why do a lot of people use them? Also, I see pointers used a lot more than references. From reading Liberty he explaines it as references work a lot better they are safer and easier to use and explain.
I don't have the "24 Hours" book...
But, I do have "Teach Yourself C++ in 21 Days", by Jesse Liberty. I found this book EXCELLENT as a beginning self-learning book. It is clearly written and easy to understand. I also like the structure provided by the questions/exercises - answers/solutions.
I have a few more advanced (and more complete) books, but when I need to look something up, I look in "21 Days" first, because if the answer is in there, it will be easy to find and easy to understand.
[EDIT]
PROBLEMS WITH THE SAMPLE CODE:
1- I do recall having to make some corrections per the errata info on the web page.
2- I couldn't print to the printer from a Windows console using his examples. This is an OS issue.
3- He does show some common non-ANSI functions (from conio.h?), but these are clearly identified.
4- At least once, I had to use the downloaded code, because I couldn't find the typo I had made when entering the code!
Re: Sams Teach Yourself in 24 hours.....
Quote:
Originally posted by RealityFusion
A question:
If pointers are such a bad thing then why do a lot of people use them? Also, I see pointers used a lot more than references. From reading Liberty he explaines it as references work a lot better they are safer and easier to use and explain.
Pointers aren't BAD per se. They're easy to misuse. There are ways to use pointers more intelligently, like using pointer wrapper classes, such as std::auto_ptr or boost::shared_ptr. The major reasons people use pointers is that pointers can be used for dynamically allocated memory, and they aren't constrained to pointing at only one object. You can make the pointer before the object itself.
Pointers and dynamic memory allocation, by themselves, are often problematic. It's very useful, but unless you take care, it's not very safe. For example, this code:
Code:
void DoSomething(){
int * ip(NULL);
float * fp(NULL);
ip = new int[25];
fp = new float[30];
/*...*/
delete[] ip;
delete[] fp;
}
is a memory leak waiting to happen. What if "fp = new float[30];" throws a std::bad_alloc? 25 integers are allocated that can never be deallocated.
Further, people aren't always smart enough to set their pointers to NULL unless they point at something valid, and THOSE problems can be a real bear to find and debug.
Overall, to make a food analogy (so sue me, I like cooking), pointers are like a sharp chef's knife -- absolutely needed for many tasks, but you need to know how to use them without cutting yourself. Wrapper classes are like hiring a professional chef for that part of the work -- he can use the knife with perfect safety, and you get the benefit.