0

Supposed I have a base class with a templated member function:

class Base {
 public:
  template <typename T>
  void Loop(T* input) {
    InnerLoop(input);
  }

 protected:
  template <typename T>
  void InnerLoop(T* input) {...}
};

I want to have a child class that implements the InnerLoop function, but it gives me a linker error

class Child : public Base {
  void InnerLoop(ConcreteType* input) {...}
};

Any way to make this work?

user4581301
  • 33,082
  • 7
  • 33
  • 54
yuzhoul
  • 131
  • 8
  • 4
    Does this answer your question? [Override template member in Interface](https://stackoverflow.com/questions/22422845/override-template-member-in-interface) – D-RAJ Jan 28 '21 at 20:12
  • 1
    Looks like you actually should get rid of `Child` and simply specialize `Base::InnerLoop` – fabian Jan 28 '21 at 20:14
  • @D-RAJ great find, but I'm too unclear on what this question's really about to hammer the question shut. Might be a better answer than "Just don't do that." once the asker clarifies their intent. – user4581301 Jan 28 '21 at 20:15
  • 1
    Also: Always include the error message in the question _as-is_. Just stating "_gives me a linker error_" isn't helpful. (I don't get a linker error for this code - but it doesn't `override` `InnerLoop` either since that can only be done with `virtual` methods as mentioned in the link @D-RAJ shared) – Ted Lyngmo Jan 28 '21 at 20:15
  • Perhaps you want something like CRTP [example](https://godbolt.org/z/jWbv6E)? – Ted Lyngmo Jan 28 '21 at 20:23

0 Answers0