c++ - Virtual base function with template return type: compiler fails at derived class with pointertype as template argument (MSVC 2013) -


if derive cbaseinterface (see code below) template argument t=int*, compiler fails wirh error c2555. happens pointer types used t. if use typedef instead, same code works fine.

// if _falis defined, compiler fails, else succeeds // (ms visual studio 2013 update 2, 32 , 64 bit native c++, debug build). #define _falis  #ifdef _falis     #define pint int*    #else     typedef int* pint; #endif  template <class t> class cbaseinterface { public:     virtual ~cbaseinterface() {}     virtual const t calculate() const = 0; };  class ccalculator : public cbaseinterface<pint> { public:     ccalculator() {}     virtual ~ccalculator() {}      // error c2555: 'ccalculator::calculate':      // overriding virtual function return type differs , not 'covariant'     // 'cbaseinterface<int *>::calculate'     virtual inline const pint calculate() const final     {        return (pint)&m_item;     }  protected:     int m_item = 0; }; 

where problem pointer types? confused , didn't find in microsoft's docs fits @ situation.

hope can me.

the difference meaning of const pint in derived class.

if pint typedef int *, const pint int * const (constant pointer mutable int) - fine, that's base class function defined return. if use macro have literally const int * (mutable pointer constant int), different type. typedef substituted logically type system, macro substituted blindly tokens.

one way rescue write pint const or const (pint) (so binding of const explicit).

and shouldn't use macros.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -