i am getting an error code C2228 with my code. this are my errors:
CODE
1>------ Build started: Project: Project 2, Configuration: Debug Win32 ------
1>Compiling...
1>clientOp2.cpp
1>c:\users\user\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(6) : error C2228: left of '.getNextItem' must have class/struct/union
1> type is 'int'
1> c:\users\user\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(3) : while compiling class template member function 'myarrayListType<elemType> myarrayListType<elemType>::operator /(const myarrayListType<elemType> &) const'
1> with
1> [
1> elemType=int
1> ]
1> c:\users\user\documents\visual studio 2005\projects\project 2\project 2\clientop2.cpp(10) : see reference to class template instantiation 'myarrayListType<elemType>' being compiled
1> with
1> [
1> elemType=int
1> ]
1>c:\users\user\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(7) : error C2228: left of '.getNextItem' must have class/struct/union
1> type is 'int'
1>c:\users\user\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(18) : error C2228: left of '.add' must have class/struct/union
1> type is 'int'
1>c:\users\user\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(19) : error C2228: left of '.getNext' must have class/struct/union
1> type is 'int'
1>c:\users\user\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(20) : error C2228: left of '.getNext' must have class/struct/union
1> type is 'int'
1>c:\users\user\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(29) : error C2228: left of '.getNext' must have class/struct/union
1> type is 'int'
1>c:\users\user\documents\visual studio 2005\projects\project 2\project 2\intersectionop.cpp(35) : error C2228: left of '.getNext' must have class/struct/union
1> type is 'int'
1>Build log was saved at "file://c:\Users\Miguel\Documents\Visual Studio 2005\Projects\Project 2\Project 2\Debug\BuildLog.htm"
1>Project 2 - 7 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
i know that the errors 2-6 i need to declare my union or my class (pretty self explanatory) but i dont know the proper syntax to do it, also, i dont know what the first error is. any help? this is my .cpp file:
CODE
template<class elemType>
myarrayListType<elemType> myarrayListType<elemType>::operator/(const myarrayListType<elemType>& rOperand) const
{
int L1, L2, L3;
L1 = L1.getNextItem();
L2 = L2.getNextItem();
// Exit when we reach the end of one
// of the lists.
while( L1 != NULL && L2 !=NULL )
{
if (L1 == L2)
{
// If the two items are equal, then they
// are in the intersection of the two lists
// so save a copy in the result list.
L3.add(L1);
L1 = L1.getNext();
L2 = L2.getNext();
}
else if (L1 < L2)
{
// If the item in list1 is less than that
// of list2, then get the next item in list1.
// This works because the lists are sorted.
// The assumption is that they are sorted from
// lowest to highest.
L1 = L1.getNext();
}
else
{
// If the item in list2 is less than that
// of list1, then get the next item in list2.
L2 = L2.getNext();
}
// We've reached the end of one list or another.
// All remaining elements of either list are not
// in the intersection of the two lists.
return L3;
}
//Complete to Return the intersection of two lists
}
and my .h file:
CODE
#ifndef H_myarrayListType
#define H_myarrayListType
#include <iostream>
#include <cassert>
using namespace std;
template<class elemType>
class myarrayListType
{
template<class elemType>
friend ostream& operator<<(ostream&, const myarrayListType<elemType>&);
public:
myarrayListType(int mS);
myarrayListType(const myarrayListType<elemType> &otherList);
~myarrayListType();
bool isEmpty();
bool isFull();
int listSize();
int insertAt(int pos, elemType item);
int retrieveAt(int pos, elemType &item);
int search(elemType item);
int remove(elemType item);
void print();
void clear();
elemType*& operator[](int);
const elemType* operator[](int) const;
myarrayListType operator+(const myarrayListType<elemType>&) const;
myarrayListType operator/(const myarrayListType<elemType>&) const;
private:
int size;
elemType **list;
int maxSize;
};
template<class elemType>
myarrayListType<elemType>::myarrayListType(int mS)
{
list = new elemType*[mS];
assert(list != NULL);
for (int i=0; i<mS; i++)
list[i] = NULL;
maxSize = mS;
size = 0;
}
template<class elemType>
myarrayListType<elemType>::myarrayListType(const myarrayListType<elemType> &otherList)
{
maxSize = otherList.maxSize;
size = otherList.size;
list = new elemType*[maxSize];
assert(list!=NULL);
for (int i=0; i<maxSize; i++)
{
if ( otherList[i] != NULL )
{
list[i] = new elemType;
assert(list[i]!=NULL);
*list[i] = *otherList[i];
}
else
list[i] = NULL;
}
}
template<class elemType>
myarrayListType<elemType>::~myarrayListType()
{
clear();
delete []list;
}
template <class elemType>
bool myarrayListType<elemType>::isEmpty()
{
if ( size == 0 )
return true;
return false;
}
template<class elemType>
bool myarrayListType<elemType>::isFull()
{
return ( size == maxSize );
}
template<class elemType>
int myarrayListType<elemType>::listSize()
{
return size;
}
template<class elemType>
int myarrayListType<elemType>::insertAt(int pos, elemType item)
{
if ( size < maxSize ) //room for one more
{
if ( list[pos] == NULL ) //empty spot
{
list[pos] = new elemType;
assert (list[pos] != NULL);
*list[pos] = item;
size++;
return pos;
}
else{ // list at pos is not empty, proceed to find an empty spot
for (int i=0; i<maxSize; i++)
{
if ( list[i] == NULL ) //empty spot
{
list[i] = new elemType;
assert (list[pos] != NULL);
*list[i] = item;
size++;
return i;
}
}
}
}
return -1;
}
template<class elemType>
int myarrayListType<elemType>::retrieveAt(int pos, elemType &item)
{
if ( list[pos] != NULL )
{
item = *list[pos];
return pos;
}
return -1;
}
template<class elemType>
int myarrayListType<elemType>::search(elemType item)
{
for (int i=0; i<maxSize; i++)
{
if ( list[i] != NULL && *list[i] == item ) //empty spot
return i;
}
return -1;
}
template<class elemType>
int myarrayListType<elemType>::remove(elemType item)
{
int pos=search(item);
if ( pos != -1 )
{
delete list[pos];
list[pos] = NULL;
return pos;
size--;
}
return -1;
}
template<class elemType>
void myarrayListType<elemType>::print()
{
for (int i=0; i<maxSize; i++)
if ( list[i] != NULL )
cout << *list[i] << " ";
cout << endl;
return;
}
template<class elemType>
void myarrayListType<elemType>::clear()
{
for (int i=0; i<maxSize; i++)
{
if ( list[i] != NULL )
delete list[i];
list[i] = NULL;
}
size = 0;
}
template<class elemType>
elemType*& myarrayListType<elemType>::operator[](int index)
{
assert(0<=index && index<maxSize);
return (list[index]);
}
template<class elemType>
const elemType* myarrayListType<elemType>::operator[](int index) const
{
assert(0<=index && index<maxSize);
return (list[index]);
}
template<class elemType>
ostream& operator<<(ostream& out, const myarrayListType<elemType>& listToPrint)
{
for (int i=0; i<listToPrint.maxSize; i++)
if ( listToPrint[i] != NULL )
out << *listToPrint[i] <<endl;
out << endl;
return out;
}
#include "unionOp.cpp"
#include "intersectionOp.cpp"
#endif