template parameter

F

funceval

Hi,

I was using llvm and came across code that looked somewhat similar to
this:

template <class U>
class LoopBase
{
};

class Loop : public LoopBase<Loop>
{
};

I didn't quite understand what this syntax means and where it might be
required. Please explain.

Thanks
 
A

Alf P. Steinbach

* funceval:
I was using llvm and came across code that looked somewhat similar to
this:

template <class U>
class LoopBase
{
};

class Loop : public LoopBase<Loop>
{
};

I didn't quite understand what this syntax means and where it might be
required. Please explain.

It's known as the Curiously Recurring Template Pattern, or CRTP for short.

Essentially it allows a kind of compile time polymorphism with LoopBase
accessing or wrapping functionality provided by the derived class.

AltaVista it.


Cheers & hth.,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,802
Messages
2,569,662
Members
45,431
Latest member
AidaVardon

Latest Threads

Top