Hej, jakiś czas nie pisałem w C++ i już musiałem coś zapomnieć bo nie potrafię sobie poradzić z pewnym problemem. Oto mój kod:
*.h
#ifndef RANGE_H_
#define RANGE_H_
class Range {
public:
class iterator {
friend class usiterator;
private:
const int m_Steep;
int m_actual;
public:
iterator(const int& limit, const int& steep);
bool operator!=(const iterator& other) const;
bool operator!=(const usiterator& other) const; //ERROR1
const int& operator*() const;
const iterator& operator++();
const iterator& operator++(int);
};
class usiterator {
friend class iterator;
private:
const int m_Value;
public:
usiterator(const int& actual);
bool operator!=(const usiterator& other) const;
bool operator!=(const iterator& other) const; //ERROR2
const int& operator*() const;
};
private:
const int m_From;
const int m_To;
const int m_Step;
public:
Range(const int& from=0, const int& to=0, const int& step=0);
iterator begin() const;
iterator end() const;
};
#endif
*.cpp
#include "Range.h"
Range::Range(const int& from, const int& to, const int& step)
: m_From(from), m_To(to), m_Step(step) {}
///----------------------------------------------------------------
Range::iterator Range::begin() const {
return iterator(m_From, m_Step);
}
///----------------------------------------------------------------
Range::iterator Range::end() const {
return iterator(m_To, m_Step);
}
///----------------------------------------------------------------
Range::iterator::iterator(const int& limit, const int& steep)
: m_actual(limit), m_Steep(steep) {
}
///----------------------------------------------------------------
bool Range::iterator::operator!=(const iterator& other) const {
if (m_Steep < 0) {
if (m_actual <= other.m_actual)
return false;
return true;
}
else {
if (m_actual >= other.m_actual)
return false;
return true;
}
}
///---------------------------------------------------------------- ERROR1:
bool Range::iterator::operator!=(const Range::usiterator& other) const {
return m_actual != other.m_Value;
}
///----------------------------------------------------------------
const int& Range::iterator::operator*() const {
return m_actual;
}
///----------------------------------------------------------------
const Range::iterator& Range::iterator::operator++() {
int temp = m_actual;
m_actual += m_Steep;
return iterator(temp, m_Steep);
}
///----------------------------------------------------------------
const Range::iterator& Range::iterator::operator++(int) {
m_actual += m_Steep;
return *this;
}
///----------------------------------------------------------------
Range::usiterator::usiterator(const int& actual)
: m_Value(actual) {}
///----------------------------------------------------------------
bool Range::usiterator::operator!=(const usiterator& other) const {
return m_Value != other.m_Value;
}
///---------------------------------------------------------------- ERROR2:
bool Range::usiterator::operator!=(const Range::iterator& other) const {
return m_Value != other.m_actual;
}
///----------------------------------------------------------------
const int& Range::usiterator::operator*() const {
return m_Value;
}
Myślę że to co projektuje nie ma to zbyt dużego znaczenia, problem jest z metodami oznaczonymi jako ERROR1 i ERROR2. Dostaję takie komunikaty kompilatora dla:
ERROR1:
Błąd (aktywny) E0493 żadne wystąpienie elementu funkcja przeciążona "Range::iterator::operator!=" nie jest zgodne z określonym typem
Błąd C2511 "bool Range::iterator::operator !=(const Range::usiterator &) const": przeciążona funkcja członkowska nie została znaleziona w "Range::iterator"
ERROR2:
Błąd C2248 "Range::iterator::m_actual": nie można uzyskać dostępu do private element członkowski zadeklarowanych w klasie "Range::iterator"
Nie wiem z czego one wynikają, przecież klasy są ze sobą zaprzyjaźnione a ciała metod są w osobnym pliku ( wobec tego nie powinno być problemów w stylu: "kompilator nie zna ciała klasy" ) .
Z góry dziękuje za pomoc i pozdrawiam :)