main.cpp
ItemType data;
DoublyIterator itor(m_List);
data = itor.Next(); // this line gives the error of the below pic

ItemType.hpp
ItemType& operator=(ItemType& data)
{
this->SetName(data.GetName());
this->SetId(data.GetId());
this->SetManufacturer(data.GetManufacturer());
return *this;
}
DoublyIterator.hpp
template
T DoublyIterator::Next() {
m_pCurPointer = m_pCurPointer->next;
return m_pCurPointer->data; // data is also of the generic template which gives ItemType in main.cpp
}

Я не могу найти, что не так с кодом, хотя оно должно быть. Ищем новые точки зрения, которые могут выявить ошибку в коде.
[Обновлено: Минимальный воспроизводимый код] — обновлено, теперь есть константные квалификаторы
Новая ошибка была задана в другом вопросе, поскольку этот вопрос был закрыт из-за дублирования.
Старая ошибка исчезла после квалификации const,
но при попытке установить имя ItemType возникает новая ошибка (и это хорошо?) из-за «EXC_BAD_ACCESS (код=2, адрес=[адрес])»
main.cpp
#include "DoublySortedLinkedList.h"
int main() {
DoublySortedLinkedList m_List;
}
ItemType.h
#include
using namespace std;
class ItemType {
public:
ItemType(int Id) {
m_Id = Id;
m_sName = "";
}
int GetId() const {
return m_Id;
}
string GetName() const
{
return m_sName;
}
void SetName(const string &inName) {
m_sName = inName;
}
void SetId(int inId) {
m_Id = inId;
}
ItemType& operator=(ItemType const &data) {
this->SetName(data.GetName());
this->SetId(data.GetId());
return *this;
}
protected:
int m_Id;
string m_sName;
};
DoubleIterator.h
#include "DoublySortedLinkedList.h"
template
struct DoublyNodeType;
template
class DoublySortedLinkedList;
template
class DoublyIterator
{
friend class DoublySortedLinkedList;
public:
DoublyIterator(const DoublySortedLinkedList& list) : m_List(list), m_pCurPointer(list.m_pFirst) {};
T Next();
private:
const DoublySortedLinkedList& m_List;
DoublyNodeType* m_pCurPointer;
};
template
T DoublyIterator::Next() {
m_pCurPointer = m_pCurPointer->next;
return m_pCurPointer->data;
}
DoublySortedLinkedList.h
#include "ItemType.h"
#include "DoublyIterator.h"
# define min ItemType(INT_MIN)
#define max ItemType(INT_MAX)
template
class DoublyIterator;
template
struct DoublyNodeType
{
T data;
DoublyNodeType* prev;
DoublyNodeType* next;
};
template
class DoublySortedLinkedList
{
friend class DoublyIterator;
public:
DoublySortedLinkedList();
private:
DoublyNodeType* m_pFirst;
DoublyNodeType* m_pLast;
int m_nLength;
};
template
DoublySortedLinkedList::DoublySortedLinkedList() {
m_pFirst->data = min; // header // this is where the new error occurs when debugging
m_pLast->data = max; // trailer // probably this will cause the error
m_nLength = 0;
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... -not-match
Мобильная версия