Wiederholungen mit Templates
#include <iostream>
using namespace std;
template<int DoNTimes, class Action>
class NTimes
{
public:
void operator()()
{
NTimes<DoNTimes-1,Action>()();
Action()();
}
};
template<class Action>
class NTimes<1,Action>
{
public:
void operator()()
{
Action()();
}
};
class HelloWorld
{
public:
void operator()()
{
cout<<"Hallo Welt!"<<endl;
}
};
void main()
{
NTimes<3, HelloWorld>()();
system("pause");
}
Kommentare zum Snippet