tags:

views:

835

answers:

2

Hello I hope someone can explain this problem. This is the code:

class Memory{
public:
   PacketPtr   pkt;
   MemoryPort* port;
   MemCtrlQueueEntry(){};

};

And after I do:

std::list<Memory*>::iterator lastIter = NULL;

And I get the following error:

 error: conversion from long int to non-scalar type std::_List_iterator<DRAMMemory::MemCtrlQueueEntry*> requested

Where is the problem, of initializing the iterator to NULL?.

+3  A: 

Iterators are not pointers. If you want to initialize them to a non-value, use list::end(). The fact that vector<T>::iterator is sometime implemented with a pointer is an implementation detail that you cannot depend on.

If you want to assign NULL to the value at the location that the iterator is refering to, you have to dereference it first:

std::list<Memory *> aList;
aList.push_back(new Memory())
std::list<Memory*>::iterator listIter = aList.begin();
delete *listIter;
*listIter = NULL;

Initializing with list::end():

std::list<Memory *> aList;
std::list<Memory*>::iterator listIter = aList.end();
Eclipse
The thing that was very strange for me is that, that code was working in another machine, is this because the fact that you metion in the beginning that "vector<T>::iterator is sometime implemented with a pointer"?
Eduardo
That's entirely possible.
Eclipse
A: 

Iterator is a class reference, not a pointer.

There is no use in initializing them except as with std::list::begin()

Quassnoi
or std::list::end()
Eclipse