I have written a wrapper class to perform insertion/removal operations on a type vector.
The code:
class GenericSymbolTable {
public:
virtual void pushBackAtom(Atom *atom) = 0;
virtual Atom* peekAtom(void) = 0;
virtual Atom* getAtom(void) = 0;
protected:
~GenericSymbolTable(void){}
};
class SymbolTable : public GenericSymbolTable {
private:
vector<Atom*> atoms;
protected:
~SymbolTable(void);
public:
void pushBackAtom(Atom *atom);
Atom* peekAtom(void);
Atom* getAtom(void);
};
When writing the implementations for those methods the compiler throws conflicting type errors:
Atom* SymbolTable::peekAtom(void) {
if(atoms.empty()) {
cout << "\t[W] Simbol table does not contain any atoms" << endl;
return NULL;
}
Atom* first = atoms.begin(); // <== type error
return first;
}
Atom* SymbolTable::getAtom(void) {
if(atoms.empty()) {
cout << "\t[W] Simbol table does not contain any atoms" << endl;
return NULL;
}
Atom* first = atoms.begin(); // <== type error
atoms.erase(atoms.begin());
return first;
}
Error msg:
cannot convert ‘std::vector::iterator {aka __gnu_cxx::__normal_iterator >}’ to ‘Atom*’ in initialization
This sets
firstequal to an iterator. You wanted to set it equal to the object the iterator points to. Try:or:
Since this is a vector of
Atom*, its iterators point toAtom*s.