Effective C++ item 5: Know what functions C++ silently writes and calls.

Share Button

If you have an empty class, compilers will declare a default constructor, a copy constructor, a copy assignment operator and a destructor for you. So

will be essentially the same as

Let’s see an example of how compiler will refuse to generate some code for you and you should write your own code explicitly.

will have such compilation errors:

It means that the compiler refuse to generate copy assignment constructor for line 20 when we are going to assign b to a. Why? The simple answer is that compilers don’t know what to do in copy constructor. Since C++ doesn’t provide a way to make a reference refer to a different object, neither can we modify a const object.

So the solution is if you want to support copy assignment in a class containing reference members or const members, you must define the copy assignment operator yourself. Finally, compilers reject implicit copy assignment operators in derived classes that inherit from base classes declaring the copy assignment operator private, in other words, if base classes prevent doing something such as copy assignment, derived classes inherit that property from base classes implicitly (unless you explicitly define copy assignment operator in derived classes). After all, compiler-generated copy assignment operators for derived classes are supposed to handle base class parts too, but in doing so, they certainly can’t invoke member functions the derived class has no right to call.

“Effective C++” Third Edition by Scott Meyers.

Keep your pans from falling off the hanger.

Share Button


Need to stop your suit trousers from falling off their hangers? Try the Savile Row fold, perfected over generations by the staff at London’s finest custom-tailoring emporiums. Start with the trousers upside down and straddling the hanger you choose. Fold one leg in through the hanger, dropping the bottom hem in between until its sit just above the crotch. Fold the second trouser leg over the first and through the hanger. Shake the hanger. Nothing happens. Clever, isn’t it?

Mount missing partitions in Ubuntu 11.10

Share Button

I found that one of my partition in windows was missing in Ubuntu, so I tried to mount it back. Firstly type:

to check what are partitions available. And I figured out that sda4 is the partition missing, so I tried

But it gave me:

Maybe it’s because auto-mount performed by Ubuntu somehow grab the handle, so I unmounted this partition first and mounted it back by:


Install opencv on linux

Share Button
  • If you don’t care about getting the cutting-edge version of opencv, you can do following:

    To compile examples:
  • If you’re geek enough to pursue newest version of everything like me, you may have to spend a little more time on this:
    To check out code from opencv svn repository: (you need to install svn first) 

     To build libraries, you need to install cmake/cmake-gui first:

    Then we can build libraries using cmake:

    In cmake-gui,  check whatever you need(if you are not sure, you can just leave it default), click configure. After “Configuring done”, click generate. If you see “Generating done”, you are good to do next step:

    Wait until it’s done.
    After you build opencv libraries, we’re ready to use them:
    Let’s begin with a hello world test program named helloWorld.cpp:

    Then we create a CMakeLists.txt in the same directory as follows:

    Then use cmake to generate makefile and use make to generate executable:

    And you are done! Run it and you’ll see a hello world window.

  • If you want to use opencv libraries in Eclipse, right click your project and select properties. In c/c++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Includes, add your opencv include dir into Include paths (-I). Then in  GCC C++ Linker -> Libraries, add libraries(such as opencv_core, opencv_highgui, your library names may var) to Libraries (-l) and your libraries dir to Library search path (-L).
    BWT, you can use these commands to locate your include files and libraries: 


OpenCV – Ubuntu Doc

OpenCV install guide

Use a Comb to Keep a Nail Steady for Hammering

Share Button


The next time you need to hammer a nail, protect your fingers with a cheap plastic comb. The tines of the comb should keep the nail tight and steady enough for you, according to Real Simple.

You’ll probably want a decent-sized comb like the one in the picture and not one of those piddly pocket combs.