クラスの中のメンバ関数の外で自分のクラス名を使わずに、自分のクラスの型をアクセスしたいです。
メンバ関数の中であれば、decltype(*this)を使ってできます。
C++
1#include <iostream> 2#include <type_traits> 3struct Foo 4{ 5 Foo() 6 { 7 typedef typename std::remove_reference<decltype(*this)>::type This; 8 std::cout << std::is_same<This, Foo>::value << std::endl; 9 } 10}; 11 12int main() 13{ 14 Foo foo; 15}
メンバ関数の外で上記のようにFooを使わずにThisを定義する術はないでしょうか?
C++
1struct Foo 2{ 3 // メンバ関数の外のここでFooを使わずにThisを定義したい。 4 typedef ????? This; 5 6 : 7 Foo() 8 { 9 typedef typename std::remove_reference<decltype(*this)>::type This; 10 std::cout << std::is_same<This, Foo>::value << std::endl; 11 } 12};
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/05/07 15:13 編集
2017/05/07 15:43
2017/05/08 05:29
2017/05/08 14:15