[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: udata / C++ / multiple inheritance
- From: "Wesley Smith" <wesley.hoke@...>
- Date: Tue, 1 Jul 2008 18:46:31 -0700
Here's my current best shot at this:
define these classes:
class Cast {
public:
virtual int cast() = 0;
};
template<class T, class B>
class Cast_op : public Cast{
public:
virtual int cast() {
T t;
char *p1 = (char *)&t;
char *p2 = (char *)((B *)&t);
return p2 - p1;
}
};
use them this way:
struct Casting {
const char *name;
Udata::Cast *cast;
};
Casting cc[] = {
{"W", new Udata::Cast_op<X, W>},
{"V", new Udata::Cast_op<X, V>},
{0, (Udata::Cast *)0}
};
printf("Cast<X, W>: %d\n", cc[0].cast->cast());
printf("Cast<X, V>: %d\n", cc[1].cast->cast());
A bit ridiculous, but it works and can be iterated over, which is what
I'm really going for.
wes