Prev: fclose and CreateFile are very slow on some machines
Next: Access violation does not call SIGSEGV handler
From: Vladimir Grigoriev on 18 Feb 2010 11:44 Let consider the following template function template <typename T> const T & f( const T &x, const T &y ) { std::cout << typeid( x ).name() << std::endl; std::cout << typeid( y ).name() << std::endl; return ( x ); } When I run this function using Borland C++ compiler adding the statements char s1[] = "ABCDE"; char s2[] = "GFHIJ"; std::cout << typeid( f( d1, s2 ) ).name() << std::endl; I get the result const char * conts char * const char * When I run the code using Microsoft C++ 2005 EE I get char const [6] char const [6] char const [6] So it is interesting what should be displayed? And if Microsoft C++ shows that the return value of f() is of type char const [6] when how does look the corresponding instantiated function? Vladimir Grigoriev std::cout << typeid( f(
From: Alex Blekhman on 19 Feb 2010 03:58 "Vladimir Grigoriev" wrote: > Thank you, Igor, very much. I was trying to place [6] before the > list of parameters and not at the end.:) The common way to cope with such nasty declarations is to use `typedef' keyword: typedef char my_buff_t[6]; const my_buff_t& f(const my_buff_t& x, const my_buff_t& y); This way you can pack the syntactic ugliness into nice descriptive type names. HTH Alex
From: Vladimir Grigoriev on 19 Feb 2010 08:49
Thanks Alex. I was trying to do the same but without using typedefs. So I got errors. Vladimir Grigoriev "Alex Blekhman" <tkfx.REMOVE(a)yahoo.com> wrote in message news:OJ4xsGUsKHA.732(a)TK2MSFTNGP06.phx.gbl... > "Vladimir Grigoriev" wrote: >> Thank you, Igor, very much. I was trying to place [6] before the list of >> parameters and not at the end.:) > > The common way to cope with such nasty declarations is to use `typedef' > keyword: > > typedef char my_buff_t[6]; > > const my_buff_t& f(const my_buff_t& x, const my_buff_t& y); > > This way you can pack the syntactic ugliness into nice descriptive type > names. > > HTH > Alex |