Skip to content

Navigation Menu

Sign in
Sign up

C++11 Programming

bellbind edited this page Oct 17, 2013 · 8 revisions

auto variable

Almost all declared statement can use only auto name = ....

  • auto i = 0;: type of i is signed int. warning occurred comparing to unsigned

anonymous function

int outer1 = ...;
int outer2 = ...;
// capture outer1 as value and outer2 as reference
auto func = [outer, &outer2](int arg1, void* arg2) -> void {
};
// type of func is "void (*func)(int, void*)"

4 type cast

  • const_cast<t>(v): remove const from const t v
  • dynamic_cast<t>(v): object down cast (runtime cast)
  • static_cast<t>(v): C down cast (compile time cast). o = static_cast(v) => t o = v
    • from void* to other pointers, use static_cast
  • reinterpret_cast<t>(v): force cast as a memory fragment

inline function with const reference arguments

For non-pointer arguments in inline function, use type const T& instead of T to avoid call copy constructor.

e.g. from:

T obj1
char* obj2
//do something with obj1 and obj2
...

as

inline void func(const T& arg1, const char* arg2) {...}
T obj1
char* obj2
//do something with obj1 and obj2
func(obj1, obj2);

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /