Skip to content

Instantly share code, notes, and snippets.

@PIlin
PIlin / crtp.cpp
Created September 1, 2015 20:48
crtp.cpp
#include <iostream>
using namespace std;
template <typename T, typename U>
struct Base
{
void TestBase(void* ptr) //__attribute__ ((noinline))
{
U& ref = *reinterpret_cast<U*>(ptr);
static_cast<T*>(this)->Test(ref);
#include <iostream>
template <typename T>
void func(T& t)
{
t.method();
}
struct A { void method() { std::cout <<"a"; } };
struct B { int justSomeValue; };
#include <iostream>
template <typename T>
void func(T& t)
{
t.method();
}
struct A { void method() { std::cout <<"a"; } };
struct B { int justSomeValue; };