诅咒 C++ 错误类
#include <iostream>
#include <conio.h>
#include <vector>
#include <cstdio>
#include "color.h"
#include <curses.h>
using namespace std;
using namespace ConsoleColor;
namespace color = ConsoleColor;
int i, n;
char input, white_space = 250, obstacle_default = 219, player=1, up_key=119, down_key=115, left_key=97, right_key=100;
class box {
int x, y, pos, pos_x, pos_y, area;
vector<int> obstacles;
public:
box (int,int);
void print (void);
void move (void);
void set_obstacles (vector<int> v);
};
int main()
{
box main_hallway(50,10);
vector<int> obstacle_list={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40};
main_hallway.set_obstacles(obstacle_list);
main_hallway.move();
return 0;
}
[...]
使用上面的代码,在包含 pdcurses 库中的curses.h 后,我立即得到这两个错误:
27: error: Expected ';'在“main_hallway”之前
28:错误:'main_hallway' 未在此范围内声明
该代码事先运行良好,但添加了 pdcurses...它似乎不喜欢与类达成一致。有办法解决这个问题吗?
其他信息:
-- Windows Vista 专业版
-- 代码::Blocks 10.04+MinGW32
-- PDCurses 3.4
#include <iostream>
#include <conio.h>
#include <vector>
#include <cstdio>
#include "color.h"
#include <curses.h>
using namespace std;
using namespace ConsoleColor;
namespace color = ConsoleColor;
int i, n;
char input, white_space = 250, obstacle_default = 219, player=1, up_key=119, down_key=115, left_key=97, right_key=100;
class box {
int x, y, pos, pos_x, pos_y, area;
vector<int> obstacles;
public:
box (int,int);
void print (void);
void move (void);
void set_obstacles (vector<int> v);
};
int main()
{
box main_hallway(50,10);
vector<int> obstacle_list={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40};
main_hallway.set_obstacles(obstacle_list);
main_hallway.move();
return 0;
}
[...]
With the above code, after including curses.h from the pdcurses libs, I immediately get these two errors:
27: error: expected ';' before 'main_hallway'
28: error: 'main_hallway' was not declared in this scope
The code worked perfectly beforehand, but with pdcurses added...it seems it doesn't like to agree with classes. Is there a way to fix this?
Additional Info:
-- Windows Vista Professional
-- Code::Blocks 10.04+MinGW32
-- PDCurses 3.4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据推测,pdcurses 中有一个 #define 在这里定义了一些标记。我猜测是
move
或print
。在 WIndows 上使用 cl /e 查看预处理器的结果。Presumable, there's a #define in pdcurses that defines some token in here. I'm guessing for
move
orprint
. Use cl /e on WIndows to see what's coming out of the preprocessor.我解决了我的问题,我需要像这样声明我的类:
而不是:
I solved my problem, I needed to declare my class like so:
rather than: