Search code examples
c++cmakeoverridingvirtual

C++ overriding void function return type causes build to fail


I am trying to convert the build system of existing code to CMake. Previously this code was compiling fine with waf. After converting the build system to CMake it fails. Any ideas?

/home/dominick/Desktop/forked/NS3/build/ns3/bridge-channel.h:54:23: error:   overriding ‘virtual std::size_t ns3::BridgeChannel::GetNDevices() const’
   virtual std::size_t GetNDevices (void) const;
                   ^~~~~~~~~~~
In file included from /home/dominick/Desktop/forked/NS3/src/csma/bindings   /ns3module.cc:1:0:
/home/dominick/Desktop/forked/NS3/src/csma/bindings/ns3module.h:2752:22: error: conflicting return type specified for ‘virtual uint32_t PyNs3CsmaChannel__PythonHelper::GetNDevices() const’

Solution

  • This should have failed in the first place. Maybe you compiled this before in 32bits and now you are building in 64bits.

    An uint32_t is not a size_t in 64bits, so you can't override it because the types are conflicting. Only if you return Base& in the base class and in the inherited class, you return a derived from Base object does this work. Never has it worked for unrelated types.

    Add override to the overriden function, in your inherited class.