errors implementing my own iterator and container

Hi,

I have some strange errors when trying to compile my own iterator and container.

this is the error:
error C2664: 'ArtikelIterator::ArtikelIterator(Artikel *)' : cannot convert parameter 1 from 'ArtikelIterator *const ' to 'Artikel *'

my container:
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
#ifndef ARTIKELCONTAINER
#define ARTIKELCONTAINER
#include "ArtikelIterator.h";
#include "Artikel.h";
class ArtikelContainer
{
public:
	ArtikelIterator head() const { return m_head; } //ERROR
	ArtikelIterator tail() const { return m_tail; } //ERROR
	void add(Artikel * a);	

private:
	ArtikelIterator * m_head;
	ArtikelIterator * m_tail;

};
#endif

void ArtikelContainer::add(Artikel * a)
{
	ArtikelIterator * it = m_head;
	while(it->next() != m_tail)
		it = it->next();
	ArtikelIterator * it2 = new ArtikelIterator(a);
	it2->nextIterator = m_tail;
	it->nextIterator = it2;
}


My iterator:
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
#ifndef ARTIKELITERATOR
#define ARTIKELITERATOR
#include "Artikel.h";
#include <iostream>
using std::ostream;
class ArtikelIterator
{
	friend class ArtikelContainer;
public:
	
	ArtikelIterator();
	ArtikelIterator(Artikel * a)
		: currentArtikel(a) {}
	ArtikelIterator(const ArtikelIterator & ai);

	ArtikelIterator* next();
	Artikel * getArtikel() const { return currentArtikel; }

	bool operator== (const ArtikelIterator & ai);
	bool operator!= (const ArtikelIterator & ai);

	friend ostream & operator<<(ostream & ostr, const ArtikelIterator & ai);
private:
	Artikel * currentArtikel;
	ArtikelIterator * nextIterator;

};
#endif

/*ArtikelIterator::ArtikelIterator(const ArtikelIterator &ai)
{
	currentArtikel = ai.getArtikel();
	nextIterator = new ArtikelIterator(ai.next());
}*/

ArtikelIterator* ArtikelIterator::next()
{
	return nextIterator;
}

ostream & operator<<(ostream & ostr, const ArtikelIterator & ai)
{
	ostr<<"\nArtikel: \n";
	ostr<<ai.getArtikel()->getNaam()<<"\t"<<ai.getArtikel()->getPrijs()<<"\n";
	return ostr;
}

bool ArtikelIterator::operator== (const ArtikelIterator & ai)
{
	return this->getArtikel() == ai.getArtikel();
}

bool ArtikelIterator::operator!= (const ArtikelIterator & ai)
{
	return this->getArtikel() != ai.getArtikel();
}


Also, can anyone validate that this is how you would define your own container and iterator ?
It's important to define my own, since it will be an exercise on the exam.
1
2
	ArtikelIterator head() const { return m_head; } //ERROR
	ArtikelIterator tail() const { return m_tail; } //ERROR 


m_head and m_tail are of type ArtikelIterator const* (the const gets
added as a result of the member function being declared const) but
the functions are declared to return a non-pointer.

This is _not_ how I would define my own container and iterator; I would
follow the paradigm used by the STL and its containers so that my container/
iterator was compatible with STL algorithms.
Topic archived. No new replies allowed.