Hey guys. I am currently experimenting with some different ideas for a Unicode string class, and I came up with a problem I just can't figure out. I hope someone else here can.
The following code has been tested on both VC++ 7.1, GCC 3.3 and Comeau (The online version), and none of them can compile it.
Basically all of them complain that the type of test is incomplete. (Although only Comeau is kind enough to let you know that's what the problem is.)Code:#include <iostream> #include <cstddef> struct utf8_tag {}; struct utf16_tag {}; struct utf32_tag {}; namespace detail { typedef std::size_t size_type; typedef unsigned int value_type; } template<typename enc> struct encoding_traits; template<> struct encoding_traits<utf32_tag> { static detail::value_type get_at_index(detail::size_type index) { return index; } }; class encoded_string { public: typedef detail::size_type size_type; typedef detail::value_type value_type; private: value_type (*get_at_index)(size_type); public: template<typename enc> encoded_string(enc dummy) { get_at_index = &encoding_traits<enc>::get_at_index; } value_type operator [] (size_type index) { return get_at_index(index); } }; int main() { encoded_string test(utf32_tag()); std::cout << test[1337] << std::endl; system("pause"); }The really strange bit though, is that if I change "encoded_string test(utf32_tag());" to "encoded_string test = utf32_tag(); Everything suddenly compiles without a hitch.Code:Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1 Copyright 1988-2003 Comeau Computing. All rights reserved. MODE:strict errors C++ "ComeauTest.c", line 52: error: expression must be a pointer to a complete object type std::cout << test[1337] << std::endl; ^ 1 error detected in the compilation of "ComeauTest.c".
Anyone care to enlighten me?




Reply With Quote