1

First of all: it is some old code to be executed on some old machines, thus I'm forced to use the ancient Visual Studio 6 and can't simply update to a newer compiler. My problem: I have an array of a structure and try to statically initialize it. This works well with all modern compilers but VC6 complains for every member it is not compatible with the struct type.

The struct is defined as

struct instData
{
   char           m_IP[MAX_IP_LENGTH];
   unsigned short m_mode;
   int            m_sock;
   double         m_prev;
};

Static initialization looks like:

static struct instData data[MAX_HEAD_NUM+1]={
    {"",0,0,0.0},
    {"",0,0,0.0},
    ...

The error messages I get are:

error C2440: 'initializing' : cannot convert from 'char [1]' to 'struct instData'
    No constructor could take the source type, or constructor overload resolution was ambiguous
error C2440: 'initializing' : cannot convert from 'const int' to 'struct instData'
    No constructor could take the source type, or constructor overload resolution was ambiguous
error C2440: 'initializing' : cannot convert from 'const int' to 'struct instData'
    No constructor could take the source type, or constructor overload resolution was ambiguous
error C2440: 'initializing' : cannot convert from 'const double' to 'struct instData'
    No constructor could take the source type, or constructor overload resolution was ambiguous

Means it complains for every member of the struct and all in first initialisation-line. So does anybody remember how such an initialisation should look like to work with VC6?

user703016
  • 37,307
  • 8
  • 87
  • 112
Elmi
  • 5,899
  • 15
  • 72
  • 143
  • The code snippets you have posted looks good to me (should compile with absolutely any compiler). Have you tried compiling it with any other compiler - either a different version of VS or something else. I'm suspecting that you have something broken in the source itself. – Mats Petersson May 26 '14 at 15:55
  • Mats Petersson: using other compilers it works well, it is definitely a VC6 bug. Found a solution meanwhile at http://stackoverflow.com/questions/11561375/array-of-structs-initialization-errors – Elmi May 26 '14 at 15:58
  • @Elmi You may want to answer your own question. – MP24 May 26 '14 at 16:27
  • Have you tried using GCC to compile it, in some old standards mode? – rubenvb May 26 '14 at 18:16

0 Answers0