Hello folks!
I'm currently doing a school assignment in C++, but so far I'm not being able to solve it. I have to implement the class message, which has a string topic, time_point timestamp and some data. However, that data may be a float value, string, boolean, or char data, and it's the task to figure out a nice way to handle these data formats. The only information I get is
I tried a bit, but so far no luck. Can anyone help me out?
My current idea is this: create 4 classes that all inherit from a Data class like this: class DataFloat : public Data { }. No idea if that works, but you also need getters and setters, so let's add some functions:
Code:
This might work for 1 class, but how would I call these functions from the main Data class? (I prefer to only have a Data member in the message class).
I'm currently doing a school assignment in C++, but so far I'm not being able to solve it. I have to implement the class message, which has a string topic, time_point timestamp and some data. However, that data may be a float value, string, boolean, or char data, and it's the task to figure out a nice way to handle these data formats. The only information I get is
Quote:
there are a few classes, one for each data type, that all inherit from a common (abstract) ancestor.
I tried a bit, but so far no luck. Can anyone help me out?
My current idea is this: create 4 classes that all inherit from a Data class like this: class DataFloat : public Data { }. No idea if that works, but you also need getters and setters, so let's add some functions:
Code:
class DataFloat : public Data {
public:
float getValue();
void setValue(float value);
private:
float value;
};
This might work for 1 class, but how would I call these functions from the main Data class? (I prefer to only have a Data member in the message class).