error: no match for 'operator=='

I have this file:

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
#include <vector>
#include <iterator>

template <typename T>
class list
{
public:
	list() {};
	~list() {}
	list operator=(T rhs[])
	{
		vect.insert(vect.being(), rhs, sizeof(rhs)); return *this;
	}
	void append(T item)
	{
		vect.push_back(item);
	}
	void insert(int position, T item)
	{
		vect.insert(vect.begin() + position, item);
	}
	int count(T item)
	{
		int total = 0;
		for (iter = vect.begin(); iter != vect.end(); ++iter)
		{
			if (*iter == vect)
			{
				total++;
			}
		}
		return total;
	}
private:
	std::vector<T> vect;
	typename std::vector<T>::iterator iter;
};


And GCC is giving me this error:

 
C:\C++\include/list.hpp:27:4: error: no match for 'operator==' in '((list<int>*)this)->list<int>::iter.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator*<int*, std::vector<int, std::allocator<int> > >() == ((list<int>*)this)->list<int>::vect'


I don't know what's wrong.

The full error: http://pastebin.com/6c3YzEYb
What are you trying to do on line 27?
Line 27 is for (iter = vect.begin(); iter != vect.end(); ++iter. I posted the entire file.
1
2
3
4
5
6
7
8
9
10
11
12
	int count(T item)
	{
		int total = 0;
		for (iter = vect.begin(); iter != vect.end(); ++iter)
		{
			if (*iter == item)
			{
				total++;
			}
		}
		return total;
	}


Also I think you should update the following function though im my opimion its semantic is wrong

1
2
3
4
	list operator=(T rhs[])
	{
		vect.insert(vect.being(), rhs, sizeof(rhs) / sizeof( *rhs ) ); return *this;
	}
Last edited on
Yeah, I meant line 27 in the code snippet you posted.
Oh. *smacks self*. These are the times I feel like I'm starting C++ all over again.
I am not sure (cannot test here).... but is it possible that the problem could be fixed replacing line 35 with

typename std::vector<T> vect;

?

Becouse the problem is surely dependant by "iter = vect.begin();" in line 25...
I have very little experiences with template and iterators, but I noticed that sometimes initializing an iterator with "begin" can be not so immediate...
list operator=(T rhs[])
{
vect.insert(vect.being(), rhs, sizeof(rhs) / sizeof( *rhs ) ); return *this;
}


here rhs is just a pointer, i don't think we can use it for finding the size ?
Topic archived. No new replies allowed.