Im calling a method foo
by const ref
:
// method, which is being called
void foo(const Entity & ent);
// call
Entity* e = new Entity;
foo(e); // wrong: missing * but compiles
This piece of code does not only compile, it creates a new instance of Entity
with its default values in the scope of foo
. I'd expect that this does not compile or at least crashes.
If I call foo
correctly (foo(*e)
), everything works as suspected and I see the right values of Entity
within foo
.
Im using mingw supplied with Qt 4.7.
Here's the interface of Entity
:
class Entity : public QObject
{
Q_OBJECT
public:
Entity (QObject* parent = NULL);
long getId() const { return this->id; }
void setId(const long id) { this->id = id; }
QString getName() const { return this->name; }
void setName(const QString & name) {this->name = name; }
private:
QString name;
long id;
};