#pragma once
#include <iostream>
#include "ArrayLinkedListRow.h"
#include "ArrayClass.h"
#include <string>
usingnamespace std;
#ifndef __ArrayLinkedList__H
#define __ArrayLinkedList__H
//#define MAX_SIZE 100
class LinkedListException: public exception{};
class LinkedListMemory: public LinkedListException{};
class LinkedListBounds: public LinkedListException{};
class LinkedListNotFound: public LinkedListException{};
template<class DT>
class ArrayLinkedList
{
private:
// DT* _info[MAX_SIZE]; // store data
// int _next[MAX_SIZE]; // next node
// int _nextEmpty[MAX_SIZE]; // next empty slot
ArrayClass< ArrayLinkedListRow<DT> >* _rows;
int _head; // head of the list
int _firstEmpty; // first empty slot
int _size;
void copy(const ArrayLinkedList<DT>& ll);//copy from another list
// add a new node with next as it's next node and returns the index of new node
int newNode( DT& newObject, int next);
public:
ArrayLinkedList(); // empty and copy constructors
ArrayLinkedList(const ArrayLinkedList<DT>& ll);
// Constructor that create a list with newObject as the head
ArrayLinkedList(DT& newObject);
// Constructor with a give capacity
ArrayLinkedList(int capacity);
// Constructor with newObject as the head and capacity
ArrayLinkedList(DT& newObject ,int capacity);
//~ArrayLinkedList(); // destructor
bool isEmpty();
// is the list empty?
int size(); // return the number of nodes stored
void add(DT& newObject);
// add an object to the tail
// insert an object at the position specified
void insertAt(DT& newObject, int position);
DT remove(); // remove the head
// remove an object at the position specified
DT removeAt(int position);
// find the object that matches key, index of the object
int find(DT key);
// = operator
voidoperator=(const ArrayLinkedList<DT>& ll);
// overloading [] operator, return a reference to object at the
// position in the linked list
DT& operator[] (constint position);
// ostream operator
template<class T> friend ostream& operator<<(ostream& s,
ArrayLinkedList<T>& ll);
// display raw data of the data members
void displayRaw();
};
template <class DT>
ArrayLinkedList<DT>::ArrayLinkedList()
{
_size = 0;
_head = 0;
_firstEmpty = 1;
}
template <class DT>
ArrayLinkedList<DT>::ArrayLinkedList(int capacity)
{
_rows = new ArrayClass<ArrayLinkedListRow<DT>>(capacity);
int hey = 3;
//************ERROR HAPPENS HERE*****************
_rows[0] = new ArrayLinkedListRow<DT>(hey,NULL,NULL);
}
template <class DT>
void ArrayLinkedList<DT>::add(DT& newObject)
{
newNode(newObject, _size);
}
template <class DT>
int ArrayLinkedList<DT>::newNode(DT& newObject, int next)
{
return -1;
}
#endif
#include <iostream>
#include <string>
#include <typeinfo>
usingnamespace std;
template <typename T>
class Foo
{
public:
T* member = new T();
void F1()
{
cout << "type name = "<< typeid(member).name()<<" and address of Foo::member is "<< member<< endl;
}
};
template<typename T>
class Bar
{
public:
T *member = new T();
void B1()
{
cout << "type name = " << typeid(member).name() << " and address of Bar::member is " << member << endl;
}
};
class FooBar
{
public:
Foo<Bar<int>> *member = new Foo<Bar<int>>();
void fooBar()
{
cout << "type name = " << typeid(member).name() << " and address of FooBar::member is " << member << endl;
}
};
//test
int main()
{
Foo<int> *foo = new Foo<int>();
foo->F1();
Bar<double> *bar = new Bar<double>();
bar->B1();
FooBar *fooBar = new FooBar();
fooBar->fooBar();
//this is equivalent to your _row
fooBar->member->F1();
system("pause");
}
_row is a pointer to memory where each index is of type ArrayClass<ArrayLinkedListRow<DT>>.
_row[0], _row[1], ....., _row[n] are of the same type.
In simpler terms..
1 2 3 4 5 6 7 8 9 10 11 12 13
//let a class...
class Foo(){};
//then..
Foo*array = new Foo(2); //NOTE THE TYPE OF array
//Then the operation
array[0] = new Foo(); // LEGAL (same type as array)
array[1] = new Bar(); // ILLEGAL. (type mismatch)
//In your terms..
ArrayClass<ArrayLinkedListRow<DT>> *_row = new ArrayClass<ArrayLinkedListRow<DT>>(capacity);
_row[0] = new ArrayClass<ArrayLinkedListRow<DT>>(); //LEGAL
_row[1] = new ArrayLinkedListRow<DT>(); //ILLEGAL . (type missmatch)