Ok so I've been trying to debug this thing for about 2 hours now and I'm stuck. Basically I have to turn this .h file which contains a class
original.h
into a .cpp/.h class files. I got so far:
new.h
new.cpp
This gives me MANY error messages mostly about the operator overloading functions. I tryed a couple of different variation but i narrowed it down to this. Basically this is a homemade vector class. If anyone knows what's wrong the help would be greatly appreciated.
BTW: Does any1 know how to find th Euclidian distance between two vectors? I know its random but I've been searching google awhile and only can find the Euclidian distance between 2 points.
Anyway thanks for all your help guys.
original.h
Code:
#ifndef MYVECTOR_H
#define MYVECTOR_H
class MyVector {
private:
double *vector;
int length;
public:
//No arg default constritor
MyVector() {}
// Constructor (initFunction)
MyVector(int size) : vector( new double [size] ), length(size) {}
// Destructor (clean up function )
virtual ~MyVector(){ delete [] vector; length=0; }
// Version used for debugging destructor!
// virtual ~MyVector(){ printf("destructor %d\n", length); if (length) delete [] vector; length=0; }
// Want to know length of vector for loops, but can't touch it
// because it is now private. Here I return a copy.
int getLength(void) const { return length; }
// Array indexing â so I can treat vector like an array
// This allows me to change the value in the vector (LHS of =)
double& operator[]( int i ) { return vector[i]; }
// Array indexing â this is read only access (RHS of =)
const double& operator[]( int i ) const { return vector[i]; }
};
#endif MYVECTOR_H
into a .cpp/.h class files. I got so far:
new.h
Code:
#ifndef MYVECTOR_H
#define MYVECTOR_H
class MyVector
{
private:
double *vector;
int length;
public:
MyVector();
MyVector(int size);
virtual ~MyVector();
int getLength(void);
double& operator[](int i);
const double& operator[](int i);
}
#endif MYVECTOR_H
new.cpp
Code:
#include "myvector.h"
MyVector::MyVector(){}
MyVector::MyVector(int size):vector(new double [size]), length(size){}
MyVector::virtual ~MyVector(){delete [] vector; length = 0; }
int MyVector:: getLength(void) const {return length;}
double& MyVector::operator[](int i){return vector[i];}
const double& MyVector:: operator[](int i) const {return vector[i]}
This gives me MANY error messages mostly about the operator overloading functions. I tryed a couple of different variation but i narrowed it down to this. Basically this is a homemade vector class. If anyone knows what's wrong the help would be greatly appreciated.
BTW: Does any1 know how to find th Euclidian distance between two vectors? I know its random but I've been searching google awhile and only can find the Euclidian distance between 2 points.
Anyway thanks for all your help guys.