Template object initialization

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'ArrayLinkedListRow<DT> *' (or there is no acceptable conversion)

Whats the correct way to initialize _rows?
ArrayClass acts the same as an array.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#pragma once
#include <iostream>
#include "ArrayLinkedListRow.h"
#include "ArrayClass.h"
#include <string>
using namespace 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
    void operator=(const ArrayLinkedList<DT>& ll);
    
    // overloading [] operator, return a reference to object at the
    // position in the linked list
    DT& operator[] (const int 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 
Last edited on
ask a more specific question
Edited
Last edited on
Look at this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <string>
#include <typeinfo>
using namespace 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) 


Last edited on
Topic archived. No new replies allowed.