1

首先:这是一些旧代码要在一些旧机器上执行,因此我被迫使用古老的 Visual Studio 6,不能简单地更新到更新的编译器。我的问题:我有一个结构数组并尝试静态初始化它。这适用于所有现代编译器,但 VC6 抱怨它与struct类型不兼容的每个成员。

struct定义为

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

静态初始化如下所示:

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

我收到的错误消息是:

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

意味着它抱怨结构的每个成员以及所有在第一个初始化行中的成员。那么有人记得这样的初始化应该如何与 VC6 一起工作吗?

4

0 回答 0