1
我無法在VS2010中編譯以下程序。保持編譯無盡並進入堆不可用。任何幫助深表感謝。編譯VS2010中的C++元程序
#include <iostream>
class function_t
{
public:
virtual void operator()()=0;
};
class greet_t : public function_t
{
public:
virtual void operator()(){ std::cout << "hello world" << std::endl;}
};
template<int count, function_t** f> class loop_t
{
public:
static inline void exec()
{
(*(*f))();
loop_t< count-1, f>::exec();
}
};
function_t* f;
int _tmain(int argc, _TCHAR* argv[])
{
f = new greet_t();
loop_t<1, &f>::exec();
return 0;
}
這是正確的。元編程高度遞歸使用,和遞歸一樣,您總是需要一個循環終止符。 – DanDan
非常感謝。 – Rajamohan