[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

legal code?

john

12/10/2008 6:45:00 PM

Someone in another list posted this code. It compiles in G++ and
apparently is absorbed by comeau as well. VS vomits.

#include <cstddef>

template < typename T, std :: size_t sz >
struct Block
{
typedef T type[ sz ][ sz ];
};

template < typename T >
void assign( T & assignee, const T & value )
{}

template < typename T, std :: size_t sz >
void assign( T ( & assignee )[ sz ], const T ( & value )[ sz ] )
{}

int main( )
{
Block< int, 16 > :: type a;
const Block< int, 16 > :: type b = { };

assign( a, b );
}


1>e:\dev_workspace\experimental\boost_msg_test\boost_msg_test\boost_msg_test.cpp(22)
: error C2782: 'void assign(T (&)[sz],const T (&)[sz])' : template
parameter 'T' is ambiguous
1>
e:\dev_workspace\experimental\boost_msg_test\boost_msg_test\boost_msg_test.cpp(14)
: see declaration of 'assign'
1> could be 'const int [16]'
1> or 'int [16]'
1>e:\dev_workspace\experimental\boost_msg_test\boost_msg_test\boost_msg_test.cpp(22)
: error C2782: 'void assign(T &,const T &)' : template parameter 'T' is
ambiguous
1>
e:\dev_workspace\experimental\boost_msg_test\boost_msg_test\boost_msg_test.cpp(10)
: see declaration of 'assign'
1> could be 'const int [16][16]'
1> or 'int [16][16]'


G++ compiles and calls the T[] version.