作者在 2011-01-02 01:32:32 发布以下内容
template <typename T>
class InterfaceT
{
public:
InterfaceT(void)
{
}
virtual ~InterfaceT(void) = 0
{
}
T t;
};
class InterfaceA
{
public:
virtual ~InterfaceA(void) = 0 {}
virtual void TestFun1(void) = 0;
virtual void TestFun2(void) = 0;
};
#define TEST 1
#if TEST == 1
class BigBen
: public InterfaceT<int>
, public InterfaceA
#else
class BigBen
: public InterfaceA
, public InterfaceT<int>
#endif
{
public:
BigBen(void)
{
}
virtual ~BigBen(void)
{
}
virtual void TestFun1(void)
{
printf("TestFun1\n");
}
virtual void TestFun2(void)
{
printf("TestFun2\n");
}
private:
char m_buf[3068];
};
void TestFun1(void* _p)
{
((InterfaceA*)_p)->TestFun1();
}
void TestFun2(void* _p)
{
((InterfaceA*)_p)->TestFun2();
}
int _tmain(int argc, _TCHAR* argv[])
{
BigBen bb;
TestFun1(&bb);
TestFun2(&bb);
system("pause");
return 0;
}
一个void*可以秒杀一切吗?上面的测试程序不管TEST是1还是0都可以编译,但是如果TEST为1时运行就会出Access violation错误。凌晨1点半了,头晕。哪位高手帮忙解答!!谢谢