Code bị lỗi: "binary '<': 'const _Ty' does not define this operator or a conversion to a type acceptable to the predefined operator"

Em mới học cntt được 1 năm, giờ có cái code mà nó bị lỗi:

C2676	binary '<': 'const _Ty' does not define this operator or a conversion to a type acceptable to the predefined operator.

Em không biết sửa sao hết, mong mọi người giúp đỡ, em cảm ơn nhiều ạ.
Đây là code của em:

#include <iostream>
#include <cmath>	
#include <map>
#include <string>
using namespace std;

struct ToaDo
{
	int x = -1;
	int y = -1; //Xác định tọa độ
	int Key = -1; //Xác định tường hay đường
};
struct Node
{
	ToaDo info;
	Node* pNext;
	Node* pPrev;
};
struct Queue_Stack
{
	Node* pHead;
	Node* pTail;
};
Node* getNode(ToaDo a)
{
	Node* t = new Node;
	t->info = a;
	t->pNext = NULL;
	t->pPrev = NULL;
	return t;
}
void Init(Queue_Stack& QS)
{
	QS.pHead = QS.pTail = NULL;
}
Node* Top(Queue_Stack Q)
{
	return Q.pHead;
}
void Pop(Queue_Stack& QS)
{
	if (QS.pHead != NULL)
	{
		Node* temp = QS.pHead;
		QS.pHead = QS.pHead->pNext;
		temp->pNext = NULL;
		delete temp;
	}
}
void Push_back(Queue_Stack& Q, Node* t)
{
	if (Q.pHead == NULL)
		Q.pHead = Q.pTail = t;
	else
	{
		Q.pTail->pNext = t;
		Q.pTail = t;
	}
}
void Push_front(Queue_Stack& Q, Node* t)
{
	if (Q.pHead == NULL)
		Q.pHead = Q.pTail = t;
	else
	{
		t->pNext = Q.pHead;
		Q.pHead = t;
	}
}
bool CheckPoint(ToaDo** a, int ChieuCao, int ChieuRong, ToaDo xx)
{
	if (xx.x < 0 || xx.x >= ChieuCao)
		return 0;
	else
	{
		if (xx.y < 0 || xx.y >= ChieuRong)
			return 0;
		else
		{
			if (xx.Key == 1)
				return 0;
			else
				return 1;
		}
	}
}
bool CheckInQueue(Queue_Stack Q, ToaDo a)
{
	if (Q.pHead != NULL)
	{
		Node* t = Q.pHead;
		while (t != NULL)
		{
			if (t->info.x == a.x && t->info.y == a.y)
				return 1;
			else
				t = t->pNext;
		}
		return 0;
	}
	return 0;
}
void BFS(ToaDo** a, ToaDo Start, ToaDo End, int ChieuCao, int ChieuRong)
{
	Queue_Stack Open;
	Queue_Stack Close;
	Init(Open);
	Init(Close);
	map<ToaDo, ToaDo> Parent;
	Node* Pstart = getNode(Start);
	Node* Pend = getNode(End);
	Push_back(Open, Pstart);
	Node* p = Top(Open);
	while (Open.pHead != NULL && p->info.Key != 3)
	{
		Node* p = Top(Open);
		Push_front(Close, p);
		Pop(Open);
		ToaDo Up = a[p->info.x - 1][p->info.y];
		ToaDo Right = a[p->info.x][p->info.y + 1];
		ToaDo Down = a[p->info.x + 1][p->info.y];
		ToaDo Left = a[p->info.x][p->info.y - 1];
		if (CheckPoint(a, ChieuCao, ChieuRong, Up) && !CheckInQueue(Open, Up) && !CheckInQueue(Close, Up))
		{
			Node* pUp = getNode(Up);
			Push_back(Open, pUp);
			Parent[Up] = p->info;
		}
		if (CheckPoint(a, ChieuCao, ChieuRong, Right) && !CheckInQueue(Open, Right) && !CheckInQueue(Close, Right))
		{
			Node* pRight = getNode(Right);
			Push_back(Open, pRight);
			Parent[Right] = p->info;
		}
		if (CheckPoint(a, ChieuCao, ChieuRong, Down) && !CheckInQueue(Open, Down) && !CheckInQueue(Close, Down))
		{
			Node* pDown = getNode(Down);
			Push_back(Open, pDown);
			Parent[Down] = p->info;
		}
		if (CheckPoint(a, ChieuCao, ChieuRong, Left) && !CheckInQueue(Open, Left) && !CheckInQueue(Close, Left))
		{
			Node* pLeft = getNode(Left);
			Push_back(Open, pLeft);
			Parent[Left] = p->info;
		}
	}
	if (p->info.Key != 3)
	{
		int PathLegth = 1;
		ToaDo Child = Parent[p->info];
		while (Child.Key != 2)
		{
			Child.Key = 4;
			PathLegth++;
			Child = Parent[Child];
		}
		cout << "\nDo dai duong di: " << PathLegth;
	}
}
void DFS(ToaDo** a, ToaDo Start, ToaDo End, int ChieuCao, int ChieuRong)
{

}
void PathFindingALL(ToaDo** a, ToaDo Start, ToaDo End, int ChieuCao, int ChieuRong)
{

}
int main()
{
	int ChieuRong, ChieuCao;
	ToaDo** a;
	ToaDo Start, End;
	Start.Key = Start.x = Start.y = -1;
	End = Start;
	cout << "Nhap chieu rong ban do (so cot): ";
	cin >> ChieuRong;
	cout << "Nhap chieu cao ban do (so hang): ";
	cin >> ChieuCao;

	a = new ToaDo * [ChieuCao];
	for (int i = 0; i < ChieuCao; i++)
		a[i] = new ToaDo[ChieuRong];

	cout << "Nhap ban do: \n";
	for (int i = 0; i < ChieuCao; i++)
	{
		for (int j = 0; j < ChieuRong; j++)
		{
			cin >> a[i][j].Key;
			a[i][j].x = i;
			a[i][j].y = j;
			if (a[i][j].Key == 2)
			{
				Start.Key = a[i][j].Key;
				Start.x = a[i][j].x;
				Start.y = a[i][j].y;
			}
			if (a[i][j].Key == 3)
			{
				End.Key = 3;
				End.x = a[i][j].x;
				End.y = a[i][j].y;
			}
		}
	}
	if (Start.Key == -1 || End.Key == -1)
		cout << "Khong co diem bat dau/ket thuc.";
	else
	{
		cout << "HELLO";
		/*
		cout << "\nBan muon lam gi?";
		cout << "\n0. Tim duong di ngan nhat?\n1. Tim duong di binh thuong?\n2. Tim duong di qua 1 diem?\n3. Tim tat ca duong di?";
		int Choose;
		cin >> Choose;
		if (Choose == 0)
		{
			BFS(a, Start, End, ChieuCao, ChieuRong);
		}
		if (Choose == 1)
		{
			DFS(a, Start, End, ChieuCao, ChieuRong);
		}
		if (Choose == 2)
		{
			cout << "\nNhap toa do diem can di qua:";
			ToaDo c;
			int m, n;			
		}
		if (Choose == 3)
		{
			PathFindingALL(a, Start, End, ChieuCao, ChieuRong);
		}
		*/
	}
	
	return 0;
}

Lỗi có chỉ đến dòng nào không? Mình xem qua đoạn mã của bạn thì không thấy cói định danh _Ty đâu cả. Bạn xem có phải nằm trong tập tin khác không?

1 Like

Để dùng được std::map thì type 1 phải có operator< vì nó là tree.

4 Likes

unordered_map thì lại phải cần hash<ToaDo> nha :V

chủ thớt chôm code ở đâu thì hỏi người viết code ở đó :V Code ko compile được sao mà lại đưa cho người khác là sao :V

4 Likes

code này tui làm chứ chôm của ai đâu ??

bạn có thể giải thích rõ hơn được không ạ

Tức là bạn thêm phương thức operator<(ToaDo) vào ấy.

2 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?