R
roman.blackhammer
Any thoughts on why TPureVirtual:: VirtFun cannot call the second
method.
Two compilers choke on it. Actually one works, but only if not using
an 'ISO C++ Template Parser.'
Why would the language allow the first version, but not the second?
Thanks.
// -----------------------
#include <iostream>
class PureVirtual
{
public:
virtual void VirtFun() = 0;
};
template <long I, class T>
class TPureVirtual : public PureVirtual
{
public:
virtual void VirtFun()
{
// 1.
static_cast<T&>(*this).Done(I);
// 2.
static_cast<T&>(*this).TDone<I>();
}
};
class ImplVirtual : public TPureVirtual<1, ImplVirtual>,
public TPureVirtual<2, ImplVirtual>
{
public:
void
Done(long I)
{
std::cout << "ImplVirtual<" << I << ">:one" << std::endl;
}
template <long I> void
TDone()
{
std::cout << "ImplVirtual<" << I << ">::TDone" << std::endl;
}
};
extern "C" int
main( int argc,
const char **argv )
{
ImplVirtual impl;
TPureVirtual<1, ImplVirtual> *pv1 = static_cast< TPureVirtual<1,
ImplVirtual>* >(&impl);
pv1->VirtFun();
TPureVirtual<2, ImplVirtual> *pv2 = static_cast< TPureVirtual<2,
ImplVirtual>* >(&impl);
pv2->VirtFun();
return 0;
}
method.
Two compilers choke on it. Actually one works, but only if not using
an 'ISO C++ Template Parser.'
Why would the language allow the first version, but not the second?
Thanks.
// -----------------------
#include <iostream>
class PureVirtual
{
public:
virtual void VirtFun() = 0;
};
template <long I, class T>
class TPureVirtual : public PureVirtual
{
public:
virtual void VirtFun()
{
// 1.
static_cast<T&>(*this).Done(I);
// 2.
static_cast<T&>(*this).TDone<I>();
}
};
class ImplVirtual : public TPureVirtual<1, ImplVirtual>,
public TPureVirtual<2, ImplVirtual>
{
public:
void
Done(long I)
{
std::cout << "ImplVirtual<" << I << ">:one" << std::endl;
}
template <long I> void
TDone()
{
std::cout << "ImplVirtual<" << I << ">::TDone" << std::endl;
}
};
extern "C" int
main( int argc,
const char **argv )
{
ImplVirtual impl;
TPureVirtual<1, ImplVirtual> *pv1 = static_cast< TPureVirtual<1,
ImplVirtual>* >(&impl);
pv1->VirtFun();
TPureVirtual<2, ImplVirtual> *pv2 = static_cast< TPureVirtual<2,
ImplVirtual>* >(&impl);
pv2->VirtFun();
return 0;
}