Pointer Problem(most likely)

Hi, I seem to have a pointer problem in my code(bold) and i hope someone can explain as well as help me fix this problem.

Error
21: Fehler: request for member 'draw' in '* it.__gnu_cxx::__normal_iterator<_Iterator,
 _Container>::operator-><city**, 
std::vector<city*> >()', 
which is of pointer type 'city*' 
(maybe you meant to use '->' ?)*it->draw(scene);
          ^


city.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#ifndef CITY_H
#define CITY_H
#include "ui_mainwindow.h"
#include "mapobject.h"

class city : public MapObject
{
public:
city(float x,float y);
virtual void draw(QGraphicsScene* scene);
private:
float x;
float y;
};

city.cpp:
1
2
3
4
5
6
7
8
9
10
11
#include "city.h"

city::city(float x,float y):
x(x),y(y)
{
}
void city::draw(QGraphicsScene* scene)
{
scene->addEllipse (this->getx() , this->gety(), 3, 3, QPen (Qt :: black), QBrush (Qt :: red , Qt :: SolidPattern ));
scene->addEllipse (this->getx()+1000, this->gety(), 3, 3, QPen (Qt :: black), QBrush (Qt :: red , Qt :: SolidPattern ));
}


map.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifndef MAP_H
#define MAP_H
#include "mapobject.h"
#include <vector>
#include "city.h"
class Map
{
public:
   std::vector<city*> citylist;
private:
    Map();
    virtual ~Map();
    virtual void draw(QGraphicsScene* scene);
    virtual void add_city(city* add);
};

#endif // MAP_H


map.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "map.h"
#include <vector>
#include <string >
#include <algorithm >
using namespace std;

Map::Map()
{
}


void Map::draw(QGraphicsScene* scene)
{
    typedef vector <city*>:: iterator iterTyp ;
    for ( iterTyp it = citylist.begin(); it != citylist.end (); it ++)
   {
    *it->draw(scene); //Problem
    };
}


Is it wrong if i assume that it points to a city pointer ??
The dereference operator has a lower precedence than the arrow operator.

(*it)->...
Thanks helios that fixed the problem however the compiler now comes up with this a new error
D:\qt\Tools\QtCreator\bin\untitled\map.cpp:-1: Fehler: undefined reference to `vtable for Map'
Last edited on
Define all Map functions (destructor, add_city...).
Thanks EssGeEich it seems i forgot the destructor.
Topic archived. No new replies allowed.