Heya, I'm just creating some random stuff to kill time and I was just wondering if there was anyway to further optimize or in anyway improve the following code: (don't be discouraged by it's length, it's really easy to understand)
I believe standard headers have their own include guards.
The other include guard is missing the #define _CVECTOR_H line. As it is, you never define _CVECTOR_H. Also, identifiers beginning with the '_' character are reserved by the standard.
Also notice that you're using a macro hack to define pi, when a const double would be a much better (and type safe) option.
You might want to see about using an initialization list in your constructor(s).
Also, some operators are better left outside of the class as friends. If I am remembering correctly, operator+, operator-, operator*, and operator/ are some of them. It has to do with associativity...
The top of your file is not very efficient. This should be better:
1 2 3 4 5 6 7 8 9
#ifndef _CVECTOR_H
#define _CVECTOR_H // remember to make this define
// place your includes inside your include guards
#include <cmath> // do not conditionally include them
class CVector
{