我想呼叫operator id () const下面的方法,該方法由 C opreate撰寫
struct CKBoxedValue {
CKBoxedValue() noexcept : __actual(nil) {};
// Could replace this with !CK::is_objc_class<T>
CKBoxedValue(bool v) noexcept : __actual(@(v)) {};
CKBoxedValue(int8_t v) noexcept : __actual(@(v)) {};
CKBoxedValue(uint8_t v) noexcept : __actual(@(v)) {};
CKBoxedValue(int16_t v) noexcept : __actual(@(v)) {};
CKBoxedValue(uint16_t v) noexcept : __actual(@(v)) {};
CKBoxedValue(int32_t v) noexcept : __actual(@(v)) {};
CKBoxedValue(uint32_t v) noexcept : __actual(@(v)) {};
CKBoxedValue(int64_t v) noexcept : __actual(@(v)) {};
CKBoxedValue(uint64_t v) noexcept : __actual(@(v)) {};
CKBoxedValue(long v) noexcept : __actual(@(v)) {};
CKBoxedValue(unsigned long v) noexcept : __actual(@(v)) {};
CKBoxedValue(float v) noexcept : __actual(@(v)) {};
CKBoxedValue(double v) noexcept : __actual(@(v)) {};
CKBoxedValue(SEL v) noexcept : __actual([NSValue valueWithPointer:v]) {};
CKBoxedValue(std::nullptr_t v) noexcept : __actual(nil) {};
// Any objects go here
CKBoxedValue(__attribute((ns_consumed)) id obj) noexcept : __actual(obj) {};
// Define conversions for common Apple types
CKBoxedValue(CGRect v) noexcept : __actual([NSValue valueWithCGRect:v]) {};
CKBoxedValue(CGPoint v) noexcept : __actual([NSValue valueWithCGPoint:v]) {};
CKBoxedValue(CGSize v) noexcept : __actual([NSValue valueWithCGSize:v]) {};
CKBoxedValue(UIEdgeInsets v) noexcept : __actual([NSValue valueWithUIEdgeInsets:v]) {};
operator id () const {
return __actual;
};
private:
id __actual;
};
uj5u.com熱心網友回復:
您可以像呼叫operator id() const;任何其他成員函式一樣呼叫用戶定義的轉換函式:
// (Assuming `x` is some value of type `CKBoxedValue`)
x.operator id();
但它通常在型別轉換期間呼叫,例如:
// Explicit conversions:
id(x)
static_cast<id>(x)
id value(x);
// Implicit conversions:
// With `void function_taking_an_id(id arg);`
function_taking_an_id(x)
id value = x;
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/397891.html
標籤:C
下一篇:位移一個浮點數
