Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否可以将int添加到一对中? 这是C和C++中的有效操作吗?< /P>_C++_C_Type Conversion - Fatal编程技术网

是否可以将int添加到一对中? 这是C和C++中的有效操作吗?< /P>

是否可以将int添加到一对中? 这是C和C++中的有效操作吗?< /P>,c++,c,type-conversion,C++,C,Type Conversion,daysgoneby+=月[monthindex]。天 基本上,将一个字段从一个查找表添加到一个int(在本例中,它是一个int到一个int,所以看起来是有效的) 其中daysgoneby的类型为int,而monthindex[monthindex]。day指下表 如果不是,为什么?如何使用表中的int类型来避免这种情况 struct Monthpairs // Fields for month & day lookup { const

daysgoneby+=月[monthindex]。天

基本上,将一个字段从一个查找表添加到一个int(在本例中,它是一个int到一个int,所以看起来是有效的)

其中daysgoneby的类型为int,而
monthindex[monthindex]。day
指下表

如果不是,为什么?如何使用表中的int类型来避免这种情况

struct Monthpairs                       // Fields for month & day lookup
{
    const char* mon;                    // Months
    int day;                            // Days
};

Monthpairs months[] =                   // Lookup table for months & day
{
    {"Jan", 31},
    {"Feb", 28},
    {"Mar", 31},
    {"Apr", 30},
    {"May", 31},
    {"Jun", 30},
    {"Jul", 31},
    {"Aug", 31},
    {"Sep", 30},
    {"Oct", 31},
    {"Nov", 30},
    {"Dec", 31},
};

您的语句非常好,最后查找表中的
day
字段也是一个
int


关于问题的标题,虽然在对中使用特定字段是可以的(只要类型对于运算符/函数是正确的),但不能添加到对本身,因为其类型与运算符期望的类型不匹配。

您的语句非常好,最后,查找表中的
day
字段也是一个
int


关于问题的标题,虽然在对中使用特定字段是可以的(只要类型对于运算符/函数是正确的),但不能添加到对本身,因为其类型与运算符期望的类型不匹配。

是。你可以这样做。那很好,
monthindex.[monthindex]。day
也是一个
int
。没问题。编辑对已删除评论的响应。斯利!你不是在对中添加int,而是在尽可能自然地添加int。除非你的问题是如何做同样的事情而不去引用结构的
部分?是的。你可以这样做。那很好,
monthindex.[monthindex]。day
也是一个
int
。没问题。编辑对已删除评论的响应。斯利!你不是在对中添加int,而是在尽可能自然地添加int。除非你的问题是如何做同样的事情而不去引用结构的
部分?