読者です 読者をやめる 読者になる 読者になる

Haruyuki Mohri

毛利春幸のブログです。

C++Builder XE8 "template metaprogramming" Try "recursive call"

Using a template a C++ try "recursive call".

C++ can use the same template class in the template class. 

template <int N>
class TFoo{
public:
    static const int value = N + TFoo<N + 1>::value;
};
This is infinitely loop.
but it is possible to make the conditions.
 
class TFoo<11>{
public:
      static const int value = 0;
};

It will add the above conditions.

 

Edit1->Text = IntToStr(TFoo<1>::value);

get out 55.

f:id:mojeld:20150707182750p:plain

1+2+3+4+5+6+7+8+9+10 = TFoo<1>::value

 

repetitions is, to many a compile error