我的代码有什么问题吗? (pdcurses/getmaxyx)
它在 getmaxyx 行(主函数中的第二行)上给了我一个访问冲突,并且还给了我这两个警告:
LINK : warning LNK4049: locally defined symbol "_stdscr" imported
LINK : warning LNK4049: locally defined symbol "_SP" imported
是的,它与我问的另一个问题中的代码相同,只是我让它更清楚。是的,我以前用 pdcurses 编写过程序,没有任何问题。
#include <time.h>
#include <curses.h>
#include "Ball.h"
#include "Paddle.h"
#include "config.h"
int main(int argc, char *argv[])
{
int maxY, maxX;
getmaxyx(stdscr, maxY, maxX);
Paddle *paddleLeft = new Paddle(0, KEY_L_UP, KEY_L_DOWN);
Paddle *paddleRight = new Paddle(maxX, KEY_R_UP, KEY_R_DOWN);
Ball *ball = new Ball(paddleLeft, paddleRight);
int key = 0;
initscr();
cbreak();
noecho();
curs_set(0);
while (key != KEY_QUIT)
{
key = getch();
paddleLeft->OnKeyPress(key);
paddleRight->OnKeyPress(key);
}
endwin();
return 0;
}
It gives me an access violation on the getmaxyx line (second line in the main function) and also gives me these two warnings:
LINK : warning LNK4049: locally defined symbol "_stdscr" imported
LINK : warning LNK4049: locally defined symbol "_SP" imported
Yes, it's the same code as in another question I asked, it's just that I'm making it more clear. And yes, I have written programs with pdcurses before with no problems.
#include <time.h>
#include <curses.h>
#include "Ball.h"
#include "Paddle.h"
#include "config.h"
int main(int argc, char *argv[])
{
int maxY, maxX;
getmaxyx(stdscr, maxY, maxX);
Paddle *paddleLeft = new Paddle(0, KEY_L_UP, KEY_L_DOWN);
Paddle *paddleRight = new Paddle(maxX, KEY_R_UP, KEY_R_DOWN);
Ball *ball = new Ball(paddleLeft, paddleRight);
int key = 0;
initscr();
cbreak();
noecho();
curs_set(0);
while (key != KEY_QUIT)
{
key = getch();
paddleLeft->OnKeyPress(key);
paddleRight->OnKeyPress(key);
}
endwin();
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经很长时间没有使用curses了,但我猜你需要在
getmaxyx
等任何其他curses调用之前调用initscr()
>。另外,您可能还缺少对 initscr 返回的一些错误检查,并且需要正确使用返回值(也许您必须将其传递给其他curses方法?)。
It has been a long time since I have used curses, but I would guess you need to call
initscr()
before any other curses call likegetmaxyx
.Also, you probably are also missing some error checking on the return of initscr and need to use the return values properly (perhaps you have to pass it on to other curses method?).
您需要在
getmaxyx
之前调用initscr
You need to call
initscr
beforegetmaxyx