이CRTP 나는 순수 가상 클래스 <code>Interface</code>의 원인이 segfault의
template<typename T>
class AbstractInterface : public Interface {
public:
void open() override;
void close() override;
void read_is_complete(const vector<byte_array>);
protected:
explicit AbstractInterface(const string params);
virtual ~AbstractInterface() noexcept;
}
그런 다음 인터페이스의 구현이를 그 다형성을 위해 CRTP를 사용합니다 :
class SPInterface : public AbstractInterface<SPInterface> {
public:
explicit SPInterface(const string params);
virtual ~SPInterface() noexcept;
void open();
void close();
void read_is_complete(const vector<byte_array> data);
}
나는 insta SPInterface
의 NCE :
unique_ptr<Interface> intf;
intf.reset(new SPInterface("aaa"));
이 범위를 벗어나 분들께 차례로 AbstractInterface
에 close 메소드를 호출하는 소멸자 AbstractInterface
를 호출 한 후이 this
에 세그먼테이션 폴트 (segfault) : 이미 I로 혼란
template<typename T>
void AbstractInterface<T>::close() {
static_cast<T *>(this)->close();
params_ = "";
}
클래스의 인스턴스를 만들었습니다. lldb 확인을 위해 보인다
AbstractInterface<SPInterface>::close(this=<unavailable>)
기본 클래스의 소멸자에서 파생 클래스의 메서드를 호출하려고해도 안전합니까? – skypjack
나는 당신이 거기에 요점을 가지고 있다고 생각합니다 :) – ruipacheco