C 모듈을 C++ 클래스로 캡슐화하려고합니다. C 구현에클래스 정적 멤버에서 정적 변수를 참조하는 방법은 무엇입니까?
내가 트링있어
const BIGNUM *BN_value_one(void)
{
static const BN_ULONG data_one = 1L;
static const BIGNUM const_one =
{ (BN_ULONG *)&data_one, 1, 1, 0, BN_FLG_STATIC_DATA };
return (&const_one);
}
이 소멸자가 일부 해제 조치
class BigNumber
{
struct deleter
{
void operator() (BIGNUM *it)
{
BN_free(it); // The freeing operation provided by origin C library
}
};
using BN_ptr = std::unique_ptr<BIGNUM, deleter>;
/* The OpenSSL BIGNUM pointer */
BN_ptr bn;
public:
BigNumber() : bn(BN_new(), ::BN_free) {}
BigNumber(BigNumber &&other) : bn(std::move(other.bn)) {}
BigNumber(const BigNumber &other) : bn(BN_new(), ::BN_free)
{
::BN_copy(bn.get(), other.bn.get());
}
BigNumber(BIGNUM *src) : bn(src, ::BN_free) {}
static const BigNumber one()
{
static const BigNumber o(const_cast<BIGNUM *>(::BN_value_one()));
return o;
}
}
를하고있는 클래스의 정적 메서드를 만들 수있는 const 정적에 대한 포인터를 returing하는 기능이있다
unique_ptr
메서드를 BN_value_one
의 정적 변수로 반환하기 때문에 반환 값을 소멸시킬 때 세그먼트 화 오류가 발생합니다.
이러한 파괴 또는 더 나은 캡슐화를 방지하는 방법이 있습니까?
'unique_ptr'을 사용하지 않으시겠습니까? –
아마도 'BN_ptr'에 마법의'one()'값을 감싸고 싶다면 일관된 인터페이스를 가질 수 있을까요?함수가 호출 될 때마다 새로운 'one'값을 만들어야하거나 다른 래퍼 클래스를 사용해야 할 것입니다. 여기'unique_ptr'을 사용하는 것이 필수입니까? – Rook