EDITED:
This question has already been asked here
but didn't help in my case. I'm trying to have a hierarchy of classes, with inherited public update()
functions. But I want a given derived derived class to call the functionality of all of its base classes before doing its own processing. My actual VS2013 solution consists of an EXE project that references a DLL project, but the simplified code below still produces the error:
// Map.h (in DLL project)
namespace Game2D {
class Map {
public:
explicit Map();
~Map();
void update(double);
protected:
virtual void baseUpdates(double dt) {}
};
}
// Map.cpp (in DLL project)
namespace Game2D {
Map::Map() { }
Map::~Map() {}
void Map::update(double dt) {
baseUpdates(dt);
// Do some base stuf...
}
}
// AutoScrollMap.h (in DLL project)
namespace Game2D {
class AutoScrollMap : public Map {
public:
explicit AutoScrollMap();
~AutoScrollMap();
protected:
virtual void baseUpdates(double) {}
};
}
// AutoScrollMap.cpp (in DLL project)
namespace Game2D {
AutoScrollMap::AutoScrollMap() : Game2D::Map() {}
AutoScrollMap::~AutoScrollMap() {}
void AutoScrollMap::baseUpdates(double dt) {
// Do some stuff...
}
}
// DesertMap.h (in EXE project)
namespace Shooter {
class DesertMap : public Game2D::AutoScrollMap {
public:
explicit DesertMap();
~DesertMap();
protected:
virtual void baseUpdates(double);
};
}
// DesertMap.cpp (in EXE project)
namespace Shooter {
DesertMap::DesertMap() : Game2D::AutoScrollMap() {}
DesertMap::~DesertMap() {}
void DesertMap::baseUpdates(double dt) {
AutoScrollMap::baseUpdates(dt);
// Do more specific stuff...
}
}
This gives me a compiler error of "error C2084: function 'void Game2D::AutoScrollMap::baseUpdates(double)' already has a body". The article above says I can use this syntax to call a function that is being overloaded. However, the base function in its example was public, not protected, and I really want to keep baseUpdates() protected since its not part of the interface.
I thought this problem was a fairly basic use of the OOP inheritance paradigm, so what am I missing? All advice is greatly appreciated!