So I have a base class that is made to hold a string value, and be able to add characters onto it:
class TextInput
{
public:
std::string value;
void add(char c)
{
if (!value.empty())
{
value += c;
}
else
{
value = c;
}
}
std::string getValue()
{
return value;
}
};
Then an inherited class, which is the same as parent but should only allow you to add numeric values to the string:
class NumericInput : public TextInput
{
public:
TextInput input;
void add(char c)
{
if (isdigit(c))
{
input.add(c);
}
}
std::string getValue()
{
return value;
}
};
What I want to know is, when called like this in my tests:
#ifndef RunTests
int main()
{
TextInput* input = new NumericInput();
input->add('1');
input->add('a');
input->add('0');
std::cout << input->getValue();
}
#endif
Why does the call to add still only use the base add class? I would assume this to use the child NumericInout class since it is being created as one, but when debugging it still only uses the parent class and I don't understand why?