0

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);
  }

};

  • 3
    `WINDOW` is an [opaque data type](https://en.wikipedia.org/wiki/Opaque_data_type). You should not really access internal data of it, only use the functions. – Some programmer dude Dec 08 '22 at 12:13
  • Strange, the tutorial I followed was doing like I did, thank you btw – Leonardo Rosati Dec 08 '22 at 12:29
  • 1
    That would personally make me start to wondering about the quality of that tutorial. The good thing is that there are *many* tutorials and references about ncurses. :) For example [this one](https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/) which I've used myself many times. – Some programmer dude Dec 08 '22 at 12:56

1 Answers1

1

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:

  • getmaxx does exactly what you want, but it is intended for legacy applications (such as BSD curses)
  • getmaxyx is the X/Open Curses equivalent which combines getmaxx and getmaxy.

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.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105