no default constructor

I have a reference in my superclass constructor. How would I do this in the subclass constructors? If I leave them empty I get a 'no default constructor' error.

1
2
3
4
GameObject::GameObject(ObjectManager& ObjectManager ) : pObjectManager(ObjectManager)
{
}


thanks!
1
2
3
Bazooka::Bazooka(ObjectManager& objectManager) : GameObject(objectManager)
{
}
Last edited on
Is pObjectManager actually a reference, or a pointer, as the name suggests? I will assume it's a reference like you said.
And is GameObject the base class, with pObjectManager being a member of the base class?

Assuming the above, you'd do something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class ObjectManager { };

class GameObject {
  public:
    GameObject(ObjectManager& ObjectManager)
    : pObjectManager(ObjectManager) { }
        
    ObjectManager& pObjectManager; // (misleading name, imo)
};

class SubObject : public GameObject {
   public:
     SubObject(ObjectManager& ObjectManager)
     : GameObject(ObjectManager) { }
};

int main()
{
    ObjectManager obj_man;
    SubObject sub_obj(obj_man);
}

Last edited on
@Mrsoap

Please don't start new topics about the same subject, just keep the original one going. Basically it's a time waster for those who reply. Please see this as being a constructive & friendly reminder :+)

We look forward to seeing your new questions :+)
Topic archived. No new replies allowed.