私はそれが私はそれが何を意味し、typedef T *QScopedPointer::*RestrictedBool;
を理解することに苦労しています午後12時37このtypedefはどのように機能しますか?
template<typename T, typename cleanup = QScopedPointerDeleter<T>>
class QScopedPointer{
typedef T *QScopedPointer::*RestrictedBool; // how does this work?
//why not QScopedPointer<T> since QScopedPointer is a template?
public:
inline operator RestrictedBool() const
{
return isNull()? Q_NULLPTR : &QScopedPointer::d;
}
inline bool isNull() const{ return !d;}
protected:
T *d;
};
でこのコードのスニペットを示し、このCPP雷がvideo 話を見ているのですか?
類似のクラスF
を作成しましたが、コンパイルされません。class QScopedPointer
とclass F
の2つのtypedefの違いは何ですか?
template<typename T>
class F{
typedef T *F::*bool;
public:
operator bool(){return true;}
};
Proのヒント:その型を使って格納されている値を見てください: '&QScopedPointer :: d'はメンバポインタへのポインタです。 'typedef'の構文は' typedef 'です。注意RestrictedBoolは新しい名前であり、typedef内の新しい名前として 'bool'を使うことはできません。クラステンプレートパラメータは、独自のクラス定義内には必要ありません。 –
chris