Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overloaded method with template

Tags:

c++

I've got the following classes:

class A: public Util<double> {}

class B: public Util<double>, public Interface {}

template<class T>
class MyTmp {
public:
    void foo(const A& a);
}


class MyClass: public MyTmp<Other> {
public:
   void foo(const B& b);
}

When I call foo using an instance of MyClass with a A object for unknown reason the foo method of MyClass is called instead of foo of class MyTmp. I'm using gcc 4.4.2 using -O3. Any tips?

like image 212
greywolf82 Avatar asked Jan 28 '26 02:01

greywolf82


1 Answers

Member functions in derived classes with the same names as those in base classes hide the functions in the base class.

If you want MyTmp<T>::foo to be available from MyClass, you could as a using-directive:

class MyClass: public MyTmp<Other> {
public:
   using MyTmp::foo;
   void foo(const B& b);
}
like image 121
TartanLlama Avatar answered Jan 30 '26 18:01

TartanLlama



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!