문제

I'm making an ncurses application, and I've come accross something that's puzzling.

If you have a struct with a member named "refresh" that is a function pointer, and you call that function later, you will get the following compile-time error:

main.c:20:10: error: ‘Point’ has no member named ‘wrefresh’
     point.refresh();

Here's a little test you can try to compile:

#include <ncurses.h>

typedef struct PointStruct Point;

void Point_refresh() {

}

struct PointStruct {
    int x;
    int y;
    void (*refresh)();
};

int main() {
    Point point;
    point.x = 0;
    point.y = 0;
    point.refresh = &Point_refresh;
    point.refresh();
}

That will give you the error mentioned above. However, if you take out the first line that includes ncurses, it will compile with no issues.

What is the reason that this does not work with ncurses, and is there a way around it? It's not really a big deal, just a slight annoyance that I have to rename that member.

도움이 되었습니까?

해결책

Because refresh() is a "pseudo-function" #defined by curses as a macro for wrefresh(win), so the preprocessor is going to replace all occurrences of that word in your source. There's no sensible way round it other to #undef it, and always use wrefresh() instead.

다른 팁

Replace:

 point.refresh();

With:

(point.refresh)();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top