darin%meer.net ed54e4945c vtable_hide
git-svn-id: svn://10.0.0.236/trunk@149976 18797224-902f-48f8-a5cc-f745e15eee43
2003-12-03 07:50:05 +00:00

71 lines
1.3 KiB
C++

// vim:set cindent:
#include <stdio.h>
#include "shim.h"
#include "inner.h"
class Outer
{
private:
Shim shim;
public:
Outer() { ShimCtor(&shim); }
~Outer() { ShimDtor(&shim); }
void foo(int x) { ShimFoo(&shim, x); }
void bar(int x, const char *s) { ShimBar(&shim, x,s); }
};
class ExtImpl : public Inner
{
public:
ExtImpl() {}
virtual ~ExtImpl()
{
printf(" -- ExtImpl::~ExtImpl [this=%p]\n", this);
}
virtual void foo(int x)
{
printf(" -- ExtImpl::foo [this=%p x=%d]\n", this, x);
}
virtual void bar(int x, const char *s)
{
printf(" -- ExtImpl::bar [this=%p x=%d s=\"%s\"]\n", this, x, s);
}
};
int main()
{
printf("\ntest use of our class directly:\n\n");
{
Outer outer;
outer.foo(10);
outer.bar(10, "hello");
}
printf("\n\ntest use of embedders class, interpreted as if it were our class:\n\n");
{
ExtImpl *ext = new ExtImpl();
Outer *outer = reinterpret_cast<Outer *>(ext);
outer->foo(5);
outer->bar(5, "world");
delete outer;
}
printf("\n\ntest use of our class, interpreted as if it were abstract class:\n\n");
{
Outer *outer = new Outer();
Inner *inner = reinterpret_cast<Inner *>(outer);
inner->foo(1);
inner->bar(1, "crazy");
delete inner;
}
printf("\n");
return 0;
}