【问题标题】:error: member access into incomplete type 'WINDOW' (aka '_win_st')错误:成员访问不完整类型 \'WINDOW\'(又名 \'_win_st\')
【发布时间】:2022-12-11 05:04:59
【问题描述】:

我在访问 _maxx 时遇到问题,它说:./ScoreBoard.hpp:20:38: 错误:成员访问不完整类型“WINDOW”(又名“_win_st”) mvwprintw(score_win, 0, score_win->_maxx - 10, "%11llu", score); ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/curses.h:322:16: 注意:'_win_st' 的前向声明 typedef 结构 _win_st WINDOW;

这是我的代码:

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

};

【问题讨论】:

  • WINDOWopaque data type。你不应该真正访问它的内部数据,只使用函数。
  • 奇怪,我遵循的教程就像我做的那样,谢谢顺便说一句
  • 这会让我个人开始怀疑该教程的质量。好处是有许多关于 ncurses 的教程和参考资料。 :) 例如this one,我自己用过很多次。

标签: c++ ncurses member-access


【解决方案1】:

如评论中所述,WINDOW 可能不透明。这是 ncurses 的一个可配置特性,在 MacOS SDK 中使用。在curses.h 的顶部,您可能会看到

/* 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"

不透明March 2007 添加了功能:

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

除了使用 WINDOW 结构的成员,还有一些函数可以让您读取数据:

  • getmaxx 完全符合您的要求,但它适用于遗留应用程序(例如 BSD curses)
  • getmaxyx 是组合了getmaxxgetmaxy 的 X/Open Curses 等价物。

X/Open Curses 没有具体说明WINDOW(或其他类型)是否不透明,但也没有提及_maxx等结构体成员。便携式应用程序应该更喜欢标准化的功能。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多