You can have a function with the same name as the class name.. ok, can someone please explain this 'ArrayC1D' function:
PHP Code:
class ArrayC1D {
public:
ArrayC1D (int *s);
~ArrayC1D ();
void input (char *msg);
ArrayC1D *transfer (ArrayC1D *old);
change (int index, int value);
int add ();
private:
int *a;
int *size;
};
ArrayC1D::ArrayC1D (int *s) { //constructor
size = s;
a = new int [*s];
}
ArrayC1D::~ArrayC1D () { //destructor
delete [] a;
}
void ArrayC1D::input (char *msg) {
//here goes the body of void input
}
ArrayC1D * ArrayC1D::transfer (ArrayC1D *old) {
int i;
for (i=0; i<*size; i++)
*a++ = *old->a++;
a = a - *size //reset array to start
old->a = old-> - *size;
return this;
}
ArrayC1D::change (int index, int value) {
a [index] = value;
}
int ArrayC1D::add () {
//here goes the body of add
}
My other question is that how come with other functions you either say void or their datatype, but with 'change' (see above) you don't say anything?
Thanks for your help,
Linette