Virtual methods and subclasses in c++
<p>So i'm trying to better understand virtual methods.
I have a base class <strong>Sensor</strong> and several subclasses <strong>SensorTemp</strong> *<em>SensorPh</em>* <strong>SensorOrp</strong></p>

<pre><code>class Sensor
{
public:
virtual void updateValue();
}
</code></pre>

<p>the subclasses then override updateValue with their own method definitions (this happens in each of the subclasses)</p>

<p>.h file</p>

<pre><code>#include "Sensor.h"
class SensorTemp : public Sensor
{
 private:


 public:

};
</code></pre>

<p>.Cpp file</p>

<pre><code>#include "Sensor.h"
#include "SensorTemp.h"
void Sensor::updateValue(){
    int reading = analogRead(pinId); 
    float voltage = reading * 5.0;
    voltage /= 1024.0;
    currentVal = voltage * 100 ;
    Serial.print("temp: "); Serial.println(currentVal);
}
</code></pre>

<p>My issue is this works for the first subclass declaration, although the following will have a compiler error: updateValue() .... first defined here ld.exe : : Disabling relaxation: it will not work with multiple definitions</p>

<p>So I'm stuck on what type of approach I should take if I want to define the method differently from each subclass?</p>

<p>Any insight would be highly appreciated!</p>
