没有成员编译错误 [英] has no member compilation error

查看:159
本文介绍了没有成员编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


错误:'list_item_t'没有名为'state'的成员


任何有创意的想法如何让这段代码无需警告和错误而编译?


$ b $

  #if defined(_DEBUG_)
#define ASSERT assert
#else / * _DEBUG_ * /
#定义ASSERT(exp)((void)(exp))
#endif`

typedef struct list_item {
struct list_item * p_next;
struct list_item * p_prev;
#ifdef _DEBUG_
int state;
#endif
} list_item_t;

main(int argc,char * argv)
{
list_item_t p_list_item;

ASSERT(p_list_item.state == 0);


解决方案

Just #define ASSERT as

 #如果已定义(_DEBUG_)
#define ASSERT断言
#else
#define ASSERT(exp)(void)0
#endif

请注意,这可能会改变其他代码点的行为,因为 ASSERT 不再评估其参数,但这就是人们期望它行为的方式。



或者执行 _DEBUG _ 构建,但这并不能解决问题,它只是避免它。


I have the following code and when I'm trying to compile it, I get an error:

error: ‘list_item_t’ has no member named ‘state’

Any creative ideas how to make this piece of code compile without warnings and erros?

 #if defined (_DEBUG_)
 #define ASSERT       assert
 #else                           /* _DEBUG_ */
 #define ASSERT( exp ) ((void)(exp))
 #endif`

typedef struct list_item {
        struct list_item *p_next;
        struct list_item *p_prev;
 #ifdef _DEBUG_
        int state;
 #endif
 } list_item_t;

main(int argc, char *argv)
{
    list_item_t p_list_item;

    ASSERT(p_list_item.state == 0);
}

解决方案

Just #define ASSERT as

 #if defined (_DEBUG_)
 #define ASSERT       assert
 #else                          
 #define ASSERT( exp ) (void)0
 #endif

Note that this may change the behaviour of other code spots because ASSERT no longer evaluates its argument, but that's how people expect it to behave anyway.

Or perform a _DEBUG_ build, but this doesn't resolve the problem, it just avoids it.

这篇关于没有成员编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆