Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef VECTOR_H_INCLUDED
- #define VECTOR_H_INCLUDED
- #include <stdarg.h>
- // brings n variables into array
- template <class V>
- void vars2array( V &array, int n, ... )
- {
- va_list params;
- va_start( params, n );
- if( sizeof( array ) / sizeof( V ) > n )
- return;
- for( int i = 0; i < n; i++ )
- {
- array[n] = va_arg( params, V );
- }
- }
- // a class to work with vectors
- class CVector
- {
- public:
- // Variables
- int x, y; // the coordinates
- // Constructor
- CVector(){ x = 0; y = 0; }; // used inside of class
- CVector( int, int ); // used for the calcing
- // Operator Overloads
- CVector operator + ( CVector );
- CVector operator + ( int[] );
- CVector operator - ( CVector );
- CVector operator - ( int[] );
- CVector operator = ( CVector );
- CVector operator = ( int[] );
- };
- CVector::CVector( int x, int y )
- {
- this->x = x;
- this->y = y;
- }
- CVector CVector::operator+ ( CVector param )
- {
- CVector temp;
- temp.x = this->x + param.x; // used this for abridgment
- temp.y = this->y + param.y; // s.o.
- return( temp );
- }
- /// @param coord[] - index 0 is x, index 1 is y
- CVector CVector::operator+ ( int coord[] )
- {
- CVector temp;
- temp.x = this->x + coord[0];
- temp.y = this->y + coord[1];
- return( temp );
- }
- CVector CVector::operator- ( CVector param )
- {
- CVector temp;
- temp.x = this->x - param.x; // s.o.
- temp.y = this->y - param.y; // s.o.
- return( temp );
- }
- /// @param coord[] - index 0 is x, index 1 is y
- CVector CVector::operator- ( int coord[] )
- {
- CVector temp;
- temp.x = this->x - coord[0];
- temp.y = this->y - coord[1];
- return( temp );
- }
- CVector CVector::operator= ( CVector param )
- {
- return( param ); // because we want it to be param
- }
- /// @param coord[] - index 0 is x, index 1 is y
- CVector CVector::operator= ( int coord[] )
- {
- CVector temp( coord[0], coord[1] );
- return( temp );
- }
- #endif // VECTOR_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement