开发者

has no member compilation error

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 AS开发者_Python百科SERT( 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.


Your class has the mentioned member if and only if _DEBUG_ is defined, and it apparently isn't.

#define _DEBUG_

in the beginning of your TU or change project settings to define it in some other way


This is due to

#define ASSERT( exp ) ((void)(exp))

which evaluates p_list_item.state == 0 and thus needs state to exist even when _DEBUG_ is not #define'd.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜