c++ - use of undefined template type -
in following code
template<unsigned bits_count, typename ut_t, typename udt_t, template <typename> class meta_t> struct uint_t { typedef uint_t<bits_count, ut_t, udt_t, meta_t> t; typedef ut_t ut; typedef udt_t udt; typedef meta_t<t> meta; ut comp[meta::array_count]; }; namespace mxi { template<typename type> struct basic_info { static const bool is_native = true; static const bool is_signed = (type(-1) < type(0)); static const int num_of_bytes = sizeof(type); static const int num_of_bits = sizeof(type) * 8; }; template<unsigned bits_count, typename ut_t, typename udt_t, template <typename> class meta_t> struct basic_info< uint_t<bits_count, ut_t, udt_t, meta_t> > { static const bool is_native = false; static const bool is_signed = false; static const int num_of_bytes = bits_count / 8; static const int num_of_bits = bits_count; }; template<typename t> struct isizeof { static const int value = sizeof(t) * 8; }; template<typename t> struct num_of_dec_digits_in_type { static const int value = int(isizeof<t>::value * 0.301f); }; template <typename type> struct default_meta { static const int array_count = basic_info<type>::num_of_bits / isizeof<typename type::ut>::value; static const int dec_digits_count = num_of_dec_digits_in_type<type>::value; }; } int main() { typedef uint_t<128, unsigned short int, unsigned int, mxi::default_meta> uint128_t; int = uint128_t::meta::dec_digits_count; int b = mxi::num_of_dec_digits_in_type<uint128_t>::value; }
gcc 4.8.1 compiles without problem, visual c++ 2008 sp1 compile following error:
line (40): error c2027: use of undefined type 'uint_t<bits_count,ut_t,udt_t,meta_t>' [ bits_count=128, ut_t=unsigned short, udt_t=unsigned int, meta_t=mxi::default_meta ] line(46) : see reference class template instantiation 'mxi::isizeof<t>' being compiled [ t=uint_t<128,unsigned short,unsigned int,mxi::default_meta> ] line(54) : see reference class template instantiation 'mxi::num_of_dec_digits_in_type<t>' being compiled [ t=uint_t<128,unsigned short,unsigned int,mxi::default_meta> ] line(11) : see reference class template instantiation 'mxi::default_meta<type>' being compiled [ type=uint_t<128,unsigned short,unsigned int,mxi::default_meta> ] line(63) : see reference class template instantiation 'uint_t<bits_count,ut_t,udt_t,meta_t>' being compiled [ bits_count=128, ut_t=unsigned short, udt_t=unsigned int, meta_t=mxi::default_meta ]
how uint_t
not defined when it's first type defined in file?
note: i've stripped lot of code parts error, i.e. numbers here computed @ compile time, used them here directly keep focus in problem
well didn't understand why type not complete when i'm using complete type - i.e. uint128_t
- able find 2 solutions:
1- in num_of_dec_digits_in_type
replace isizeof<t>::value
basic_info<t>::num_of_bits
, it.
2- create new type num_of_dec_digits_in_type_size
, use instead of num_of_dec_digits_in_type
:
template<int size> struct num_of_dec_digits_in_type_size { static const int value = int(size * 0.301f); }; template <typename type> struct default_meta { . . static const int dec_digits_count = num_of_dec_digits_in_type_size< basic_info<type>::num_of_bits >::value; };
the 2nd solution modification of 1st solution.
Comments
Post a Comment