Pass in a struct to a function
Posted on 2005-03-26
How would I go about passing a struct, which looks like the following...
typedef student ItemStudentType; //student is a class
into a function that accepts a type of the same class but different name...if this doesn't make any sense, here is the function where i'm trying to pass to...
void StudentList::insert(int index,ItemType newItem) throw (ListIndexOutOfRangeException)
int newLength = getLength() + 1;
if ((index < 1) || (index > newLength))
throw ListIndexOutOfRangeException("ListOutRangeException: insert index out of range");
Node *newPtr = new Node;
if (newPtr == NULL)
throw ListException("ListException: insert cannot allocate memory");
throw ListException("ListException: maximum number of students have been reached");
size = newLength;
Node *prev = find(index-1);
I call it by this statement insert(getLength(), *objStudentNode);
Object *objStudent is instantiated by this call...StudentNode *objStudent = new StudentNode();
I should note that the insert function is a method inside a base class, which I inherit from the class in which I'm calling it from. The calling class has its own struct but with the same class.