New to c++ and i am trying to write a common function which accepts a structure with common fields. For example
struct A
{
int id,
int p_id,
json_t* ptr
}
struct B
{
int id,
int p_id,
long lg,
cha* tptr
}
struct C
{
int id,
int p_id,
int test
}
I want to use a common function which accepts any of these struct as parameter.
Can i have a common structure with id, p_id and a void* which accepts anything and in the receiving end again convert void* to required structure. Is this a correct in c++ ? or i shoud just make use of polymorphism?
struct Base
{
int id;
int p_id;
};
struct A : public Base
{
json_t* ptr;
}
struct B: public Base
{
long lg,
cha* tptr;
};
struct C : public Base
{
int test;
};