>> is there a way to only pass to foo the array, and the function will compute this value inside its scope?
What value?
>> so a pointer to corners returns me only the first element, and not everything?
No. Corners is an array of these points. The name 'corners' acts as a pointer to the first address. If you dereference this point (*corners) you get the first elements. Likewise, if you add 1 to the pointer, you get the second element *(corners + 1). This notation is inconvenient, and corners[1] is the same as *(corners + 1)
Okay. Point and vector class interfaces. Don't criticize me :>
Code:
class CPoint
{
friend class CVector; // Cuddle fluffle shnuff
friend std::istream & operator >> ( std::istream &, CPoint& );
friend std::ostream & operator << ( std::ostream &, const CPoint & );
private:
int _dimensions; // Number of used dimensions of our point
public:
double x, y, z; // Coord values - note cap on 3 dimensions
// Constructors and Destructors
// o 1-D
// o 2-D
// o 3-D
// o N-D
CPoint( void );
CPoint( int a );
CPoint( double a );
CPoint( int a, int b );
CPoint( double a, double b );
CPoint( int a, int b, int c );
CPoint( double a, double b, double c );
CPoint( int n, int * a );
CPoint( int n, double * a );
~CPoint();
// Available Operations
// o Translations
// o Scaling
// o Comparisons
bool operator == ( const CPoint & other ) const;
bool operator != ( const CPoint & other ) const;
CVector operator - ( const CPoint & other ) const;
CPoint operator + ( const CVector & translate ) const;
CPoint operator - ( const CVector & translate ) const;
CPoint & operator += ( const CVector & translate );
CPoint & operator -= ( const CVector & translate);
friend CPoint operator * ( int scaler, CPoint v );
friend CPoint operator * ( double scaler, CPoint v );
friend CPoint operator * ( CPoint v, int scaler );
friend CPoint operator * ( CPoint v, double scaler );
friend CPoint operator / ( CPoint v, int scaler );
friend CPoint operator / ( CPoint v, double scaler );
friend CPoint operator + ( CPoint v, CPoint w );
// General
friend double distance( const CPoint & a, const CPoint & b );
int getDimensions( void ) const;
int setDimensions( int dim );
};
class CVector : public CPoint
{
public:
// Constructors and Destructors
// o 1-D
// o 2-D
// o 3-D
// o N-D
CVector( void );
CVector( int a );
CVector( double a );
CVector( int a, int b );
CVector( double a, double b );
CVector( int a, int b, int c );
CVector( double a, double b, double c );
CVector( int n, int * a );
CVector( int n, double * a );
~CVector( void );
CVector negate( void ) const;
CVector perp( void ) const;
// Arithmatic Operators
// o Scaling
// o Transformations
// o Cross product
// o 2-D 'perp' product
// o 3-D cross product
friend CVector operator * ( int scaler, CVector v ); // S
friend CVector operator * ( double scaler, CVector v ); // C
friend CVector operator * ( CVector v, int scaler ); // A
friend CVector operator * ( CVector v, double scaler ); // L
friend CVector operator / ( CVector v, int scaler ); // I
friend CVector operator / ( CVector v, double scaler ); // N'
CVector operator + ( const CVector & v ) const; // VSUB
CVector operator - ( const CVector & v ) const; // VADD
double operator * ( const CVector & v ) const; // Dot
double operator | ( const CVector & v ) const; // Perp
CVector operator ^ ( const CVector & v ) const; // Cross
CVector & operator *= ( double scaler ); // Scale
CVector & operator /= ( double scaler ); // Scale
CVector & operator += ( const CVector & v ); // VADD
CVector & operator -= ( const CVector & v ); // VSUB
CVector & operator ^= ( const CVector & v ); // Cross Product
// o Norm
// o Normalize
double norm( void );
void normalize( void );
};
Oh right. Context. I designed these classes for my own use, and if you don't want to reinvent the wheel, I can provide the implementation that I made if you want.