クラステンプレートCの様に、クラステンプレート内にエイリアステンプレートを記述すると、クラステンプレートDから、それを型として使用するときに、typenameを記述しないとコンパイルエラーになります。
この様な場合でも、エイリアス宣言した型をtypenameなしで使用する方法は、ないのでしょうか。
B_tの様に、クラステンプレート外に記述されたエイリアステンプレートは、テンプレートクラスDで、typenameなしで使用できるので、同じ様にtypenameなしで記述できないのかと思いました。
C++
1#include <iostream> 2#include <array> 3#include <algorithm> 4 5template <typename type> 6class A { 7public: 8 typedef std::array<type, 3> A_t; 9}; 10 11template <typename type> 12using B_t = std::array<type, 3>; 13 14template <typename type> 15class C { 16public: 17 using C_t = std::array<type, 3>; 18}; 19 20template <typename type> 21class D { 22public: 23 typename A<type>::A_t a = {0, 1, 2}; 24 B_t<type> b = {3, 4, 5}; 25 typename C<type>::C_t c = {6, 7, 8}; 26}; 27 28int main() { 29 D<int> d; 30 std::for_each(d.a.begin(), d.a.end(), [](const auto& e) { std::cout << e << std::endl; }); 31 std::for_each(d.b.begin(), d.b.end(), [](const auto& e) { std::cout << e << std::endl; }); 32 std::for_each(d.c.begin(), d.c.end(), [](const auto& e) { std::cout << e << std::endl; }); 33}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/03/18 16:23 編集
2016/03/18 16:37 編集
2016/03/18 16:37