Tagged: c++ Toggle Comment Threads | Keyboard Shortcuts

  • Yogi S. 22:31 on 2013/05/03 Permalink | Reply
    Tags: c++   

    Some curious facts about C++ 

    I am reading and learning about C++ and rvalue references and move semantics and stuff like that. Here are some things that took me by surprise.

    Some rvalues can appear on the left side of an assignment operator. This, in hindsight, is less surprising than it looks. Let us say TClass is a class, and f() returns an object (by value) of type TClass. Then, we are used to calling f().someFunctionOnTClass() all the time. Assignment is another function called on the object, so it is like f().operator=(otherObject). It is kind of silly to call it, since the rvalue f() is temporary and changing it does not give us anything (we cannot use the changes).

    Next one is less surprising, but interesting nonetheless. Some lvalues cannot appear on the left hand side of the assignment operator. What is the example? A couple:

    • A user defined type (TClass say) that does not have operator=() defined.
    • An array.



  • Yogi S. 06:49 on 2011/09/23 Permalink | Reply
    Tags: c++   

    To use callback class member functions, you need to have a static wrapper function. You pass the instance of class (object) to this wrapper function along with arguments, which in turns passes the arguments to appropriate member function.

    Read about this on http://www.newty.de/fpt/callback.html, and then tried it.

Compose new post
Next post/Next comment
Previous post/Previous comment
Show/Hide comments
Go to top
Go to login
Show/Hide help
shift + esc