私はこのようなテンプレートクラスを持っています:
class template <class T1, class T2, class CTHIS> class cachedValuesClass
{
typedef T2 (CTHIS::*ptrToInternalMethodType)(T1) const;
ptrToInternalMethodType classFuncVar;
T2 getValue(CTHIS* _this, T1 x, bool *error = NULL) const;
}
getValueコードは、この呼び出しの「this」として_thisパラメーターを使用して、this-> classFuncVarのポイントに格納されているメソッドを呼び出すことになっています。私はこれを書いてみました:
template <class T1, class T2, class CTHIS>
T2 cachedValuesClass<T1, T2, CTHIS>::getValue(CTHIS* _this, T1 x, bool *error /*=NULL*/) const
{
return *_this.*this.*classFuncVar(x);
}
しかし、それは機能しません、私はこのエラーを受け取ります:
130|error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘((const cachedValuesClass<float, float, vocationForTheorical>*)this)->cachedValuesClass<float, float, vocationForTheorical>::classFunc (...)’, e.g. ‘(... ->* ((const cachedValuesClass<float, float, vocationForTheorical>*)this)->cachedValuesClass<float, float, vocationForTheorical>::classFunc) (...)’|
130|error: ‘this’ cannot be used as a member pointer, since it is of type ‘const cachedValuesClass<float, float, vocationForTheorical>* const’|
括弧を含むいくつかのバリエーションを試しましたが、うまくいきませんでした。この行の正しい構文はどのようにすべきですか?
前もって感謝します!
getValue
メンバー関数を呼び出す前にメソッドポインタをターゲットオブジェクトにバインドするには、メソッドコードにさらにいくつかの括弧が必要です。
return (_this->*classFuncVar)(x);
// or more complete
return (_this->*(this->classFuncVar))(x);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加