運が悪かったのでググってみたので、ここでやってみます。
いくつかのクラスがあり、それぞれがメンバーを定義していますstruct foo
。このメンバータイプ自体は、以前のクラスの1つから継承できるため、メンバータイプ自体foo
を取得できます。foo
foo
テンプレートメタプログラミング(以下を参照)を使用してネストされた型にアクセスしたいのですが、c ++名の挿入では問題が発生します。これは、上部のfoo
型の名前が下部の型に挿入され、下部のfoo
型にアクセスするときに上部の名前が解決されるためです。A::foo::foo
。
次に例を示します。
#include <type_traits>
struct A;
struct B;
struct A {
struct foo;
};
struct B {
struct foo;
};
struct A::foo : B { };
struct B::foo : A { };
// handy c++11 shorthand
template<class T>
using foo = typename T::foo;
static_assert( std::is_same< foo< foo< A > >, foo< B > >::value,
"this should not fail (but it does)" );
static_assert( std::is_same< foo< foo< A > >, foo< A > >::value,
"this should fail (but it does not)" );
参考までに、私は関数導関数を実装していますfoo
が、導関数タイプです。上記の状況は、たとえばsin/cosで発生します。
TLDR:どうすれfoo<foo<A>>
ばfoo<B>
、ではなく、どうすればいいfoo<A>
ですか?
ありがとう !