Category Archives: cpp

C++11 reading list

C++11 (formerly known as C++0x) is the most recent version of the standard of the C++ programming language. After it was approved by ISO in 2011, many books have been published to embrace the updates. Here are THREE core books that I recommend: one language tutorial, one library tutorial, and one bible.

C++ Primer (5th Edition)



Although it is called “primer”, this book is actually written for both beginners and experienced C++ programmers. The 5th Edition is fully updated and recast for C++11 standard as well. As a real tutorial of C++ programming language, it provides authoritative and comprehensive introduction to C++11. Another highlight is its huge amount of examples to help readers learn and understand the language fast.

Undefined reference to Sqrt — A quick note to compile SVM-multiclass

When I compiled SVM-multiclass using make, I got an error msg saying “undefined reference to sqrt“. I check the makefile and found that -lm is included in the gcc flags.

The trick here is to put the library AFTER the module you are compiling. The problem is a reference thing. The linker resolves references in order, so when the library is BEFORE the module being compiled, the linker gets confused and does not think that any of the functions in the library are needed. By putting the library AFTER the module, the references to the library in the module are resolved by the linker.

read more

What are the differences between pointers and references in C++?

Pointers and references look very different (pointers use * and ->, while references use .), but they seem to have the same function: both can be used to indirectly point to another object. So when should you use pointers vs. references?

The most important thing you should always remember is that, reference can never be assigned NULL directly. A reference has always to refer to an object. Therefore, if you need a variable that needs to point to nothing sometimes, then this variable should be declared as a pointer, not a reference. The fact that reference should always refer to an object makes the program more effective, because it doesn’t need to be tested null before usage.

read more