M
Martin Herbert Dietze
Hello,
I have a factory method like this:
ParentClass* ClassName::mkObject (int foo, int bar) const;
Now when I call it to create an object, g++ seems to treat this
new object as a const reference:
ParentClass *foo = mkObject (42, 42);
foo->addToFoo (42);
....results in this:
error: invalid initialization of reference of
type 'ParentClass&' from expression of type 'const ParentClass'
My understanding is that the `mkObject' method does not modify
the object on which I call it. Why should the returned object
now be a const object?
Cheers,
Martin
I have a factory method like this:
ParentClass* ClassName::mkObject (int foo, int bar) const;
Now when I call it to create an object, g++ seems to treat this
new object as a const reference:
ParentClass *foo = mkObject (42, 42);
foo->addToFoo (42);
....results in this:
error: invalid initialization of reference of
type 'ParentClass&' from expression of type 'const ParentClass'
My understanding is that the `mkObject' method does not modify
the object on which I call it. Why should the returned object
now be a const object?
Cheers,
Martin