你好!
有一段代码:
房间.h
#ifndef ROOM_H
#define ROOM_H
#include <vector>
#include <cstdlib>
#include "point.h"
using std::vector;
class Room
{
private:
int x;
int y;
int width;
int height;
vector<Point> points();
public:
bool intersects(Room other);
int area();
Room(int x_, int y_, int w, int h);
Room(){;}
Room(const Room &base){(*this) = base;}
static Room random(int fWidth, int fHeight, int maxWidth, int maxHeight, int minWidth, int minHeight);
friend bool operator==(Room a, Room b);
Room operator=(const Room &base);
};
#endif
点.h
#ifndef POINT_H
#define POINT_H
class Point
{
public:
int x;
int y;
Point(int x_, int y_)
{
x = x_;
y = y_;
}
Point()
{
;
}
};
#endif
迷宫.h
#ifndef MAZE_H
#define MAZE_H
#include <vector>
#include "room.h"
using std::vector;
enum Cell
{
Empty,
Room,
Path
};
class Maze
{
Cell *field;
bool *fog;
int width;
int height;
int area;
void putRooms(int count);
vector<Room> rooms;
public:
Maze(int w, int h);
void print(){}
};
#endif
尝试编译时,编译器会生成:
In file included from main.cpp:2:0:
maze.h:27:13: error: type/value mismatch at argument 1 in template parameter lis
t for 'template<class _Tp, class _Alloc> class std::vector'
vector<Room> rooms;
^
maze.h:27:13: note: expected a type, got 'Room'
maze.h:27:13: error: template argument 2 is invalid
In file included from maze.cpp:1:0:
maze.h:27:13: error: type/value mismatch at argument 1 in template parameter lis
t for 'template<class _Tp, class _Alloc> class std::vector'
vector<Room> rooms;
^
maze.h:27:13: note: expected a type, got 'Room'
maze.h:27:13: error: template argument 2 is invalid
同时,如果紧接着vector<Rooms> rooms;在maze.h中声明
Point x;
vector<Point> y;
没有更多的错误。
您能否解释一下 和 之间的编译器有什么区别Point,Room以及如何编译代码?
您的枚举成员也被命名
Room,这将覆盖类Room。重命名、使用命名空间或
enum class.