Thursday, July 10, 2008

C++ common errors

Collection of my favorite C++ errors.

1) incorrect typecast:
double p = 0.3333;
int N = 50000, m=30000
int dn = (int)p*M-m;
2) signed - unsigned integer improper use:
unsigned int X=45;
double x = -Х*0.5;
x == ???
3) template misuse:
class Base {}
class Derived : public Base {}

std::vector<Base> v;
Derived d;
v.push_back(d);
and the last one, my favorite:
double p = 2/3; Happy coding!