Mufe wrote:
Visual c++ compiler survives this:
#define THE_NULL -32767
struct typePair { int v2,v3; };
struct typeTriple { int v1; typePair p; };
typePair EMPTY_PAIR = {THE_NULL,THE_NULL};
typeTriple sv = {THE_NULL, EMPTY_PAIR };
Why does borland compiler return error
Cannot convert 'typePair' to 'int'
since typeTriple is defined as 2nd arg typePair.
It survives this
typeTriple sv = {THE_NULL, {THE_NULL, THE_NULL} };
Thank you
I'm not sure which version of Borland C++ or Visual C++ you have, but
that code doesn't pass on my VC++ 6.0 (sp6) or Microsoft .NET 2003 (at
dinkumware.com). It does work on g++ 3.4.1, EDG (also at
dinkumware.com), and Comeau C++ (comeaucomputing.com). Since the latter
two are the most standard compliant, it seems likely that Borland is
non-conformant at that point.
BTW, in C++, it is generally preferable to use a constructor over
array-style initialization:
struct typePair
{
typePair( int a_v2, int a_v3 ) : v2( a_v2 ), v3( a_v3 ) {}
int v2,v3;
};
struct typeTriple
{
typeTriple( int a_v1, const typePair& a_p ) : v1( a_v1 ), p( a_p )
{}
int v1;
typePair p;
};
typePair EMPTY_PAIR( THE_NULL, THE_NULL );
typeTriple sv( THE_NULL, EMPTY_PAIR );
Cheers! --M