我是新来的,我不确定我是否在做正确的事情。我想在结构中执行if else语句但是我得到了一个错误。也许像这样
menuItem_t messageCentre[] = {
if (drainUpdate == true){
{"New Message Arrived", {MENUACTION_GOTOCUSTOM, &messageDrainCustomWithData}},
else{
{"No Message", {MENUACTION_GOTOCUSTOM, &messageCentreCustomWithData}},
}
};
我也试过了
#ifdef drainUpdate
{"New Message Arrived", {MENUACTION_GOTOCUSTOM, &messageDrainCustomWithData}},
#else
{"No Message", {MENUACTION_GOTOCUSTOM, &messageCentreCustomWithData}},
#endif
但运气不好。请建议。谢谢你!
if
是一个语句,但是您需要的是一个表达式。幸运的是,有一个"如果"。表达式,称为?:
(也称为三元表达式,因为它有三个子表达式)。
menuItem_t messageCentre[] =
{
drainUpdate ? "New Message Arrived" : "No Message",
{
MENUACTION_GOTOCUSTOM,
drainUpdate ? &messageDrainCustomWithData : &messageCentreCustomWithData
}
};