c++ncursesmember-access

error: member access into incomplete type 'WINDOW' (aka '_win_st')


I have problems accessing _maxx, it says: ./ScoreBoard.hpp:20:38: error: member access into incomplete type 'WINDOW' (aka '_win_st') mvwprintw(score_win, 0, score_win->_maxx - 10, "%11llu", score); ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/curses.h:322:16: note: forward declaration of '_win_st' typedef struct _win_st WINDOW;

this is my code:

#pragma once

class Scoreboard {
  protected:
  WINDOW * score_win;
  public :
  Scoreboard(){

  }
  Scoreboard(int width, int y, int x){
    score_win = newwin(1, width, y, x);
  }
  void initialize(int initial_score){
    this->clear();
    mvwprintw(score_win, 0, 0, "Score: ");
    updateScore(initial_score);
    this->refresh();
  }
  void updateScore(int score){
    mvwprintw(score_win, 0, score_win->_maxx - 10, "%11llu", score);
  }
  void clear(){
    wclear(score_win);
  }
  void refresh(){
    wrefresh(score_win);
  }

};


Solution

  • As noted in a comment, WINDOW may be opaque. That is a configurable feature of ncurses, which is used in the MacOS SDK. Toward the top of curses.h, you may see

    /* These are defined only in curses.h, and are used for conditional compiles */
    #define NCURSES_VERSION_MAJOR 5
    #define NCURSES_VERSION_MINOR 7
    #define NCURSES_VERSION_PATCH 20081102
    
    /* This is defined in more than one ncurses header, for identification */
    #undef  NCURSES_VERSION
    #define NCURSES_VERSION "5.7"
    

    The opaque feature was added in March 2007:

            + add NCURSES_OPAQUE symbol to curses.h, will use to make structs
              opaque in selected configurations.
    

    Rather than use members of the WINDOW struct, there are functions which let you read the data:

    X/Open Curses does not specify whether WINDOW (or other types) is opaque, but it does not mention the struct members such as _maxx. Portable applications should prefer the functions which are standardized.