I have an issue where I have an interface that has parts that make sense as templated, and parts that make sense as not-templated. I'm in the middle of a refactor where I'm splitting that out into two different interfaces where the more specific (the templated one) inherits from the other one. E.g., say I have an interface IArray
, this would contain functions like Size()
since it doesn't care about the data type. But I'd have another interface ITArray<DataType>
that would have something like DataType GetElement(...)
. (This is just for illustration, don't yell at me to use std::vector). The reason I'm doing this refactor is that there are a lot of consumers of the non-templated interface and they'd like to not have to write templated functions that accept a templated interface if they don't need the templated type (generally extern "C"
stuff)
The problem is that I have overloaded functions that appear in both interfaces, but for some reason I can't resolve the base class functions. Here's a simple example that I put together that's not compiling in MSVC:
#include <iostream>
class IA
{
public:
virtual void X()=0;
};
template <class DataType>
class ITA : public IA
{
public:
//If I uncomment this line, it all works!
//virtual void X()=0;
virtual void X(DataType d)=0;
};
template <class DataType>
class A : 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 this since it's in IA, not ITA
I.X(d);
}
int main(int argc, char* argv[])
{
A<int> I;
DoSomething(I,10);
}
Is there some way that I can make IA's functions appear in ITA<> without manually putting them there? I see a maintenance nightmare ahead of me.