DomingoSL DomingoSL - 9 months ago 90
C++ Question

Conflicting return type specified for 'virtual void'

Im trying to compile an example from the Cryptosuite for Arduino. Im getting this error:

In file included from sha1test.pde:1:
C:\Program Files (x86)\Arduino\libraries\Sha/sha1.h:26: error: conflicting return type specified for 'virtual void Sha1Class::write(uint8_t)'
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/Print.h:48: error: overriding 'virtual size_t Print::write(uint8_t)'

Checking that line of the sha1.h file i got:

virtual void write(uint8_t);

I believe is expecting a different type of variable but I have no idea how to solve this.


The overriding function has a return type of void while the overridden function has a return type of size_t. That's illegal. Per the standard, "The return type of an overriding function shall be either identical to the return type of the overridden function or covariant with the classes of the functions" (C++ 10.3.5, both the 2003 and 2011 versions of the standard).

The standard goes on to discuss what it means for return types to be "covariant". That has to do with pointers and references to classes. My advice: Take the easy way out and always make the return types identical. Then you don't have to worry about whether the return types from an overridden and overriding virtual function are covariant.

In this case, void and size_t are neither identical nor covariant.