I'm starting to learn% object-oriented%, and I have to do an algorithm using threaded lists. In C++
, I used a structure that had as one of the attributes a pointer to the structure itself. I would like to know if it is possible to do something like C
, but using classes instead of structures.
Here is an example of what I intend to do:
class item {
public:
item(int profit, item *next);
~item();
insertItem(int profit, item *ptList);
returnItem(int i, int w, int W, item *ptList);//Função que retorna o objeto de uma matriz simulada com lista encadeada
private:
int profit;//Valor correspondente ao objeto
item *next;//Ponteiro para o próximo item da lista
};