0

I'm trying to override an inherited function from a base class which is also a class template, but I can't get it to work.

Up to now the base class is:

template<typename T, typename instrument>
class Probe {
private:
    instrument probe;
public:
    Probe(instrument _probe) : probe{_probe} {}
    virtual T read() const;
    instrument getProbe() const {return this->probe;}
};

While the derived class is:

class TestProbe : public Probe<int,int> {
public:
    TestProbe(int _probe) : Probe(_probe) {}
    virtual int read() const override {return getProbe();} // later will have a more complex expression
};

The error I get whenever I try to compile is: undefined reference to Probe<int, int>::read() const

  • 2
    You need to define what `Probe::read` is supposed to do. Either that, or declare it as an abstract virtual method. – Sam Varshavchik Mar 07 '20 at 01:28
  • See [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/a/12574407/9837301) (esp. the answer for class members) – JaMiT Mar 07 '20 at 02:36
  • Thank you, I defined a what `Probe::read` does and I simply wrote: `T Probe::read() const {}`. I know it's not the best way of doining it and might lead to problems if I access `TestProbe` objects as objects of their base class and call for `read` method. Any suggestion is wellcome (knowing also that `typename T` is unknown and I don't know what should I return). – MarMen1713013 Mar 08 '20 at 02:30

0 Answers0