Below is the code I have. I stripped stuff not related to the issue to keep this concise:
IChip.hpp (Root abstract class)
class IChip {
public:
virtual bool test() noexcept = 0;
};
IMemory.hpp (Abstract with some functions common to all Memories, read/write for illustration)
#include "IChip.hpp"
template <typename TAddr, typename TWord>
class IMemory: public IChip {
protected:
...
public:
virtual TWord read(const TAddr addr) const noexcept = 0;
virtual void write(const TAddr addr, const TWord data) const noexcept = 0;
...
bool test() noexcept final override;
};
IMemory.cpp
#include "IMemory.hpp"
template <typename TAddr, typename TWord>
bool IMemory<TAddr, TWord>::test() noexcept {
std::cout << "IMemory:test()" << std::endl;
...
return true;
}
// Explicit instantiation. (Actually resides in a separate file IMemory.impl.cpp, but included here for clarity)
template class IMemory<uint16_t, uint8_t>;
HM62256.hpp (again read/write for illustration)
#include "IMemory.hpp"
class HM62256: public IMemory<uint16_t, uint8_t> {
private:
...
public:
...
uint8_t read(uint16_t addr) const noexcept final override;
void write(uint16_t addr, uint8_t data) const noexcept final override;
...
};
HM62256.cpp
#include "HM62256.hpp"
uint8_t HM62256::read(uint16_t addr) const noexcept {
uint8_t result = 0;
...
return result;
}
void HM62256::write(uint16_t addr, uint8_t data) const noexcept {
...
}
main.cpp
int main(int argc, char *argv[]) {
const uint8_t ADDR_PINS[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18};
const uint8_t DATA_PINS[] = {19, 20, 21, 22, 23, 24, 25, 26};
HM62256 *device = new HM62256(ADDR_PINS, DATA_PINS, 2, 3, 27);
device->test(); // (1)
delete device;
}
My primary issue is as follows:
- This code compiles with no issues (not even warnings).
- My expectation is that
device->test()
at (1) will execute thetest()
method that HM62256 inherited from IMemory. Thus it should print IMemory:test() to the console. It does not. I set breakpoints on saidtest()
method, but the debugger does not hit them. Instead, the execution simply goes through, nothing is printed to the console. I set a breakpoint ondelete device;
and it does hit it.
My secondary issue is, since the code compiles fine, that function call at (1) must call something, right? WHAT does it call?
Additional info:
- Compiler: GCCC 8.3.0 targetting arm-linux and C++20
- Using CMake