1
CRTP를 사용하여 초기화 참조를하는 방법이 있습니까?crtp를 사용하는 초기화 참조 멤버
내 목표는
#include <iostream>
int gI = 1;
template <typename Derived>
struct A
{
A()
{
static_cast<Derived*>(this)->InitRefs();
}
void InitInt(int & i) { i = gI; }
};
struct B : public A<B>
{
B() : A<B>() {}
void InitRefs()
{
InitInt(i);
}
int & i;
};
int main()
{
B b;
std::cout << b.i;
}