使用Visual Studio 6编译时错误

时间:2014-05-26 15:34:30

标签: c++ visual-studio vc6 visual-studio-6

首先:它是在一些旧机器上执行的一些旧代码,因此我被迫使用古老的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一起使用吗?

0 个答案:

没有答案