C++ Tidbits

Type Conversion Constructor

Syntactic sugar for a constructor with a single argument. Given a class definition:

class Complex {
private:
  double real;
  double im;
public:
  Complex(int r, int i) {
    real = r;
    im = i;
  };
  Complex(int r) {
    real = r;
    im = 0;
  };
};

Complex c=5 is a sweetened version of Complex c(5).

C Include Files

#include <math.h> becomes #include <cmath>, #include <stdio.h> becomes #include <cstdio> etc. The ".h" is removed from the filename to denote the availability of a library, instead of the presence of an actual file. "c" is prefixed to libraries of the Standard C library. While these headers contain the same methods, the functions are put in the std namespace.

Post a comment

Posting is disabled due to excessive spamming.

 

Last modified on 31.07.2008 at 12:30 GMT