TOP Language C C++/CLR VC stl

Tips

abstract

class Base {
    public:
        virtual void paint() = 0;   // need to be overridden
};

cast

dynamic_cast < type-id > ( expression )run-time type check is madebase-to-derived conversions are not allowed
ex
static_cast < type-id> ( expression )No run-time type check is made to help ensure the safety of the conversionex
const_cast > type-id < ( expression )Removes the const, volatile, and __unaligned attribute(s) from a class
reinterpret_cast < type-id > ( expression )Allows any pointer to be converted into any other pointer type.a simple binary copy
[cli]::safe_cast<type-id>(expression)change the type of an expression and generate verifiable MSIL code.

static_cast
class CBase {};
class CDerived: public CBase {};
CBase * a = new CBase;
CDerived * b = static_cast<CDerived*>(a);

//non pointer conversion
double d=3.14159265;
int i = static_cast<int>(d);
dynamic_cast
class CBase { };
class CDerived: public CBase { };
CBase b; CBase* pb;
CDerived d; CDerived* pd;
pb = dynamic_cast<CBase*>(&d);     // ok: derived-to-base
pd = dynamic_cast<CDerived*>(&b);  // wrong: base-to-derived 
Wiki
予約語について

check compiler

vc#ifdef _MSC_VERVC6 – 1200
VC7 – 1300
VC8 – 1400
VC9 – 1500
vc#ifdef _MSC_FULL_VER14.00.50727.762->140050727762

copy constructor

A( const A &a );

exception

例外処理プログラミング
MSDN-C と C++ での例外処理、第 1 部
Exceptions and Error Handling
Resource acquisition is initialization RAII
... in some file
static char ERR1[]="error1";
throw ERR1
... in some other file
try {
 
} catch(char * msg){
}(...){
}

member function pointer

operator overload

samples
A &operator=( const A &a );
Overload is not allowed between two different scopes.
Sub-Class member doesn't belong to the same scope of the Super-class member with the same name.
class Base { int A(int); };
class Sub:Base { int A(char *); int A(int a){Base::A(a);} };
constructor overload
THIS WON'T WORK. A() is create and delete another A(9) instance in it. so i is still undefined.
class A {
  public:
     int i;
     A(){ A(9);}
     A(int i) { this->i = i };
};
Default parameter(below) may help, or just create a shred private function.
class A {
  public:
     int i;
     A(int i=9) { this->i = i };
};

Interface class

virtual ~destructor() = 0; // to ensure to call derived class's destructor

template

テンプレートは実装もヘッダファイルに書く
exportは実装されてないのがほとんどだそう。
G++ nonbugs
The "implicit typename" extension got removed in GCC 3.4.0
template <typename> struct A{
    typedef int X;
};
template <typename T> struct B{
    //A<T>::X          x;  // error
    typename A<T>::X y;  // OK
};
B<void> b;

Regular Expression

Reserved Words

Error Message

Source code

links of links

misc compilers

tcc

管理人/副管理人のみ編集できます