c++ - Overloading virtual functions in two different interfaces -


i have issue have interface has parts make sense templated, , parts make sense not-templated. i'm in middle of refactor i'm splitting out 2 different interfaces more specific (the templated one) inherits other one. e.g., have interface iarray, contain functions size() since doesn't care data type. i'd have interface itarray<datatype> have datatype getelement(...). (this illustration, don't yell @ me use std::vector). reason i'm doing refactor there lot of consumers of non-templated interface , they'd not have write templated functions accept templated interface if don't need templated type (generally extern "c" stuff)

the problem have overloaded functions appear in both interfaces, reason can't resolve base class functions. here's simple example put that's not compiling in msvc:

#include <iostream>  class ia { public:         virtual void x()=0; };  template <class datatype> class ita : public ia { public:         //if uncomment line, works!         //virtual void x()=0;         virtual void x(datatype d)=0; };  template <class datatype> class : public ita<datatype> { public:     void x()     {         std::cout << "in x" << std::endl;     }      void x(datatype d)     {         std::cout << "in x, d=" << d << std::endl;     } };  template <class datatype> void dosomething(ita<datatype>& i, datatype d) {     i.x(); //msvc can't resolve since it's in ia, not ita     i.x(d); }  int main(int argc, char* argv[]) {     a<int> i;     dosomething(i,10); } 

is there way can make ia's functions appear in ita<> without manually putting them there? see maintenance nightmare ahead of me.

have tried adding using directive? ia::x hidden a::x.

class : ... { public:     using ia::x;     virtual void x(datatype d) = 0;  }; 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -