dimanche 3 juillet 2016

Eclipse fails to resolve a method from a vector made of class pointers (C++)

I have a class that looks like this:

enum DATA_TYPE {bla, bla2};
class Mem_Data
{
private:
    DATA_TYPE m_eType;
    uint32    m_nLineAddr;
    uint32    m_nPhysAddr;
    uint32    m_nSize;
    int       m_nIndex;
public:
    Mem_Data(DATA_TYPE eType, uint32 nLineAddr,uint64 nPhysAddr,uint64 m_nSize, int nIndex = 0);
    DATA_TYPE GetType();
    int GetIndex();
    uint32 GetLineAddr();
    uint32 GetPhysAddr();
};

I then create a vector that is made from pointers of this class:

Vector<Mem_Data *> m_dataVec;
m_dataVec.push_back(new MemData());
m_dataVec.push_back(new MemData());
m_dataVec.push_back(new MemData());

(Of course I put data to match my constructor but this is just an example)

But when I try to access a function from the class inside the vector Eclipse fails to resolve it.

m_dataVec.begin()->GetType()

The above fails to resolve. However this seems to work:

Mem_Data *p = m_dataVec.begin();
p->GetType();

This does resolve but it seems inelegant as it forces me to add another variable and not access the class instance directly.

Would appreciate any suggestions.

Aucun commentaire:

Enregistrer un commentaire