error C2106: '=': Linker Operand have to be L value

Hi ive got a little Task to implement a Hash list without any Containers except string here now i cant find the problem could u may help me at this error?
Here is the code

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
/*
 * Hashtable.cpp
 *
 *  Created on: 30.05.2011
 *      Author: Hendrik
 */

#include "Hashtable.h"
#include "Pair.h"
#include "List.h"
#include <iostream>
using namespace std;



template<class type> 
Hashtable<type> :: Hashtable(int nsize) {
	this->size = nsize;

	this->table = new List<Pair<type> > [nsize];

	for (int i = 0; i < nsize; i++) {
		this->table[i] = List<Pair<type> > ();
	}
}



template<class type> 
Hashtable<type> :: ~Hashtable() {
	delete[] this->table;
}



template<class type> 
int Hashtable<type> :: hashcode(string key) {
	return (key[0] + key[1] * 256) % this->size;
}



template<class type> 
bool Hashtable<type> :: contains(string key) {
	int size = this->table[this->hashcode(key)].getSize();
	if (size > 0) {

		for (int i = 0; i < size; i++) {
			if (this->table[this->hashcode(key)].getValue(i).key == key) {
				return true;
			}
		}
	}
	return false;
}

template<class type> 
type Hashtable<type> :: get(string key) {

	int size = this->table[this->hashcode(key)].getSize();
	for (int i = 0; i < size; i++) {
		if (this->table[this->hashcode(key)].getValue(i).key == key) {
			return this->table[this->hashcode(key)].getValue(i).value;
		}
	}

	return 0;
}

template<class type> 
bool Hashtable<type> :: put(string key, type value) {

	Pair<type> newPair(key, value);
	if (this->contains(key)) {

		int size = this->table[this->hashcode(key)].getSize();
		for (int i = 0; i < size; i++) {
			if (this->table[this->hashcode(key)].getValue(i).key == key) {
				this->table[this->hashcode(key)].getValue(i).value = value; // Here is the Error C2106
			}
		}
		return true;

	} else {

		this->table[this->hashcode(key)].add(newPair);
		return false;
	}

}

template<class type> 
bool Hashtable<type> :: remove(string key) {
	if (this->contains(key)) {

		int size = this->table[this->hashcode(key)].getSize();
		for (int i = 0; i < size; i++) {
			if (this->table[this->hashcode(key)].getValue(i).key == key) {
				this->table[this->hashcode(key)].remove(i);
				break;
			}
		}

		return true;
	} else {
		return false;
	}
}
Do we must guess in which statement the error occured?!!!
No, i did a Comment for the error @ line 79
This error means that a structure or a class returned from a function can not be changed because it is a temporary object.

Consider the following example

1
2
3
4
5
6
7
8
9
struct B { int x; };
B g() { B b = { 10 }; return b; }

int main()
{
   g().x = 20;   // here an error shall be issued

   return 0;
}


Function g returns a temporary object of type B which then is tried to be changed. The same as I think is valid for your statement

this->table[this->hashcode(key)].getValue(i).value = value;

I think that member function getValue returns a class (or structure) and its member value is changed.

Maybe you should define the function such a way that it would return a reference to your object (class or structure) of which the value is a member.
Last edited on
closed account (zb0S216C)
Ent2 wrote:
"error C2106: '=': Linker Operand have to be L value"

An R-Value is a constant. An R-Value on the left-hand side of the assignment operator doesn't make much sense, does it? A L-Value is modifiable object which can be on the left and right hand-side of the assignment operator.

What does getValue() return? And of what type is value?

Wazzak
Last edited on
Topic archived. No new replies allowed.