Why would I get errors on something simple like:
Code:
IntArray::IntArray() with a .h declaration of IntArray()??
And I also can't seem to not "redfine" my overload functions
Code:
//.h declaration
IntArray overload=(IntArray x)
//.cpp function
IntArray IntArray::overload=(IntArray x)
{
}
I'll post the full cess pool of code below but I figured I'd spare everyone my messing stuff. It seems as though I am not supposed to use Int... cause it says int is assumed...but I thought attached to IntArray it wouldn't matter. And I haven't the slightest clue about the redefinition.....I'm doing it exactly how my instructor did in his examples so....beats me....thanks in advance.
.h file
Code:
#ifndef _INTARRAY_H
#define _INTARRAY_H
class IntArray{
private:
char* array;
int m_high;
int m_low;
public:
IntArray(); //constructor with no params 0 to 10 indices
IntArray(int x); //constructor with 1 param indices 0 to int x
IntArray(int x, int y); //constructor with 2 params indices from int x to int y, int x !> y
IntArray(IntArray x); //constructor with 1 param which is an Object of type IntArray
int high();
int low();
void operator[](int x, int y);
IntArray operator+(IntArray x, IntArray y);
IntArray operator=(IntArray x);
boolean operator==(IntArray x);
boolean operator!=(IntArray x);
IntArray operator+=(IntArray x);
#endif
.cpp file
Code:
#include <iostream>
#include "intarray.h"
using namespace std;
IntArray::IntArray()
{
const int size = 10
array = new char[size];
m_low = 0;
m_high = 10;
}
IntArray::IntArray(int x)
{
const int size = x;
array = new char[size];
m_low = 0;
m_high = size -1;
}
IntArray::IntArray(int x, int y)
{
const int size = y - x + 1;
array = new char[size];
m_low = x;
m_high = y;
}
IntArray::IntArray(intarray x)
{
const int size = x.high() - x.low();
array = new char[size];
m_low = x.low();
m_high = x.high();
}
int IntArray::high()
{
return m_high;
}
int IntArray::low()
{
return m_low;
}
//subscript operator overload
void IntArray::operator[](int x, int y)
{
}
//sum of two arrays to be assigned to a third
IntArray IntArray::operator+(IntArray x, IntArray y)
{
/*PSEUDO CODE SORTA
size = ??
for(i = low(); i <= high(); i++)
{
sumArray[i] = array1[i] + array2[i];
}
return sumArray;
Then call the operator=.....on sumArray[i]..
*/
////////////////////////////////////////////
// real code
//////////////////////////////////////////
int size1, size2, i, j, k;
size2 = y.high() - y.low();
size1 = x.high() - x.low();
if(size1 == size2)
{
size = size1;
thisArray = new char[size];
for(i=thisArray.low, j=y.low(), k=x.low(); i <= thisArray.high(); i++)
{
thisArray[i] = y[j] + x[k];
}
size2 = thisArray.high() - thisArray.low();
size1 = array.high() - array.low();
if(size1 == size2)
{
for(i=thisArray.low, j=array.low(); j <= array.high(); i++)
{
array[k]= thisArray[i];
}
}
return array;
}
else
{
cout<<"Arrays are not the same size" << endl;
wait();
}
}
IntArray IntArray::operator=(IntArray x)
{
/*
PSEUDO STUFF
Find both sizes
if size == then
run a for loop (i = low; i < high; i++)
array[i] = x.array[i];
return array;
*/
/////////////////////////////////////////////
// real code
/////////////////////////////////////////////
int size1, size2, i, k;
size2 = y.high() - y.low();
size1 = array.high() - array.low();
if(size1 = size2)
{
for(i=y.low, k=array.low; k <= array.high(); k++, i++)
{
array[i] = y[k];
}
return array;
}
else
{
cout<<"Arrays are not the same size" << endl;
wait();
}
}
boolean IntArray::operator==(IntArray x)
{
/*
Pseudo Stuff
//lengths don't have to match
if array1[i] == array2[2]
in a for loop for EXISTING ELEMENTS
return true
else
return false
use the smaller size array as condition
*/
}
boolean IntArray::operator!=(IntArray x)
{
/*
Psuedo Stuff
//lengths don't have to match
if array[i]==array2[2]
in a for loop for EXISTING ELEMENTS
return true
else
return false
use a smaller size array as condition
*/
}
IntArray IntArray::operator=+(IntArray x)
{
/*
Pseudo Stuff
find both sizes
if size== the return false
else move on
if any array1[i] != array2[2[
in a for loop for each element
return true
else return false
*/
}