I\'m doing some work in C++ for a company that has everything else written in C (using C isn\'t an option for me :( ). They have a number of data structures that are VERY simila
Yes, this isn't hard at all. Just put both an A
and an Entry
in a single object, and make the Entry
a second-class citizen:
void setDefaultValues(Entry*); // You should be able to provide these.
struct Entry {
int x;
int y;
};
struct Indirect : public Entry { };
template struct EntryOr : public T, Indirect
{
setDefaultValues(this);
};
// From C code
struct A {
int x;
}
int main()
{
EntryOr foo;
foo.x = 5; // A::x
std::cout << foo.x << foo.y; // Prints A::x and Entry::y
}
(Link)