I have an abstract struct Base with no fields (only abstract methods) and struct A, struct B inheriting from Base with different fields in both.
Is it possible to have a rule for parsing either a A or a B and store the result in a shared_ptr<Base>?
I would like to do it in order to parse some A or B and store it in a container of shared_ptr<Base>.
Here is a definition for the structs:
#include <iostream>
using namespace std;
struct Base
{
virtual void operator() const = 0;
};
struct A : Base
{
int value;
void operator() const override { cout << "Hello A: " << x << endl; };
};
struct B : Base
{
float value;
void operator() const override { cout << "Hello B: " << x << endl; };
};
struct BaseContainer
{
multimap<string, shared_ptr<Base>> container;
}
Let's say a BaseContainer is define by some input formatted like:
name: A value
name: B value
name: A value
where name is a placeholder for a string used as a key for the multimap in BaseContainer, then A or B is a keyword for generating a struct A or struct B, and value is the value stored in the container.
How would I write a parser BaseContainer?
The real example I want to apply it to is more complicated, struct A and struct B does not have same number of fields in it so please don't answer with something too specific to that example.
Thank you.