C++ 为什么即使我将结构重新定义为typedef并注释typedef行,我仍可以继续使用重写的结构?
为什么即使我将结构重新定义为typedef并注释typedef行,我仍可以继续使用重写的结构C++ 为什么即使我将结构重新定义为typedef并注释typedef行,我仍可以继续使用重写的结构?,c++,struct,C++,Struct,为什么即使我将结构重新定义为typedef并注释typedef行,我仍可以继续使用重写的结构 #include <iostream> #define MAZE_SIZE 21 #define MENU_H_SIZE 30 #define MENU_V_SIZE 120 using namespace std; char strMaze[MAZE_SIZE][MAZE_SIZE] = {}; struct _tagPlayerPos { int x; int y
#include <iostream>
#define MAZE_SIZE 21
#define MENU_H_SIZE 30
#define MENU_V_SIZE 120
using namespace std;
char strMaze[MAZE_SIZE][MAZE_SIZE] = {};
struct _tagPlayerPos
{
int x;
int y;
};
//typedef _tagPlayerPos POINT; <- here
//typedef _tagPlayerPos* PPOINT; <- here
POINT tPlayerPos;
POINT tStartPos;
POINT tEndPos;
int main()
{
setMaze(strMaze, &tPlayerPos, &tStartPos, &tEndPos
}
void setMaze(char Maze[MAZE_SIZE][MAZE_SIZE], PPOINT pPlayerPos, PPOINT pStartPos,
PPOINT pEndPos)
{
pStartPos->x = 1;
pStartPos->y = 0;
pEndPos->x = 18;
pEndPos->y = 19;
*pPlayerPos = *pStartPos;
strcpy_s(Maze[0], "02000000000000000000");
strcpy_s(Maze[1], "01111110001100000000");
strcpy_s(Maze[2], "00000011111000110000");
strcpy_s(Maze[3], "00000010010100100000");
strcpy_s(Maze[4], "00000110011111100000");
strcpy_s(Maze[5], "00000100000100000000");
strcpy_s(Maze[6], "00000100000111000000");
strcpy_s(Maze[7], "00011111000001000000");
strcpy_s(Maze[8], "00010001111100000000");
strcpy_s(Maze[9], "00010000001000000000");
strcpy_s(Maze[10], "01111000001111000000");
strcpy_s(Maze[11], "00001000000100000000");
strcpy_s(Maze[12], "00011000000111111100");
strcpy_s(Maze[13], "00010000001100000100");
strcpy_s(Maze[14], "00011111000000001100");
strcpy_s(Maze[15], "00000001000000001000");
strcpy_s(Maze[16], "00011101000111111000");
strcpy_s(Maze[17], "00000101000000000000");
strcpy_s(Maze[18], "00000111111111111110");
strcpy_s(Maze[19], "00000000000000000030");
}
#包括
#定义迷宫大小21
#定义菜单大小30
#定义菜单大小120
使用名称空间std;
字符strMaze[MAZE_SIZE][MAZE_SIZE]={};
结构
{
int x;
int-y;
};
//类型def_tagPlayerPos POINT;y=0;
pEndPos->x=18;
pEndPos->y=19;
*pPlayerPos=*pStartPos;
strcpy_s(迷宫[0],“020000000000000000000”);
strcpy_s(迷宫[1],“011111001100000000”);
strcpy_s(迷宫[2],“000000 11111 00011000”);
strcpy_s(迷宫[3],“000000 10010100100000”);
strcpy_s(迷宫[4],“0000011001111000000”);
strcpy_s(迷宫[5],“0000010000100000000”);
strcpy_s(迷宫[6],“000001000011000000”);
strcpy_s(迷宫[7],“000111100001000000”);
strcpy_s(迷宫[8],“0001000111100000000”);
strcpy_s(迷宫[9],“0001000000000000”);
strcpy_s(迷宫[10],“011100000111000000”);
strcpy_s(迷宫[11],“0000100000”);
strcpy_s(迷宫[12],“00011000111100”);
strcpy_s(迷宫[13],“00010000001000100”);
strcpy_s(迷宫[14],“000111100000001100”);
strcpy_s(迷宫[15],“0000000 1000000010000”);
strcpy_s(迷宫[16],“0001110100111000”);
strcpy_s(迷宫[17],“00000 101000000000000”);
strcpy_s(迷宫[18],“0000011111110”);
strcpy_s(迷宫[19],“00000000000000000030”);
}
为什么即使我将结构重新定义为typedef并注释typedef行,我仍可以继续使用重写的结构
#include <iostream>
#define MAZE_SIZE 21
#define MENU_H_SIZE 30
#define MENU_V_SIZE 120
using namespace std;
char strMaze[MAZE_SIZE][MAZE_SIZE] = {};
struct _tagPlayerPos
{
int x;
int y;
};
//typedef _tagPlayerPos POINT; <- here
//typedef _tagPlayerPos* PPOINT; <- here
POINT tPlayerPos;
POINT tStartPos;
POINT tEndPos;
int main()
{
setMaze(strMaze, &tPlayerPos, &tStartPos, &tEndPos
}
void setMaze(char Maze[MAZE_SIZE][MAZE_SIZE], PPOINT pPlayerPos, PPOINT pStartPos,
PPOINT pEndPos)
{
pStartPos->x = 1;
pStartPos->y = 0;
pEndPos->x = 18;
pEndPos->y = 19;
*pPlayerPos = *pStartPos;
strcpy_s(Maze[0], "02000000000000000000");
strcpy_s(Maze[1], "01111110001100000000");
strcpy_s(Maze[2], "00000011111000110000");
strcpy_s(Maze[3], "00000010010100100000");
strcpy_s(Maze[4], "00000110011111100000");
strcpy_s(Maze[5], "00000100000100000000");
strcpy_s(Maze[6], "00000100000111000000");
strcpy_s(Maze[7], "00011111000001000000");
strcpy_s(Maze[8], "00010001111100000000");
strcpy_s(Maze[9], "00010000001000000000");
strcpy_s(Maze[10], "01111000001111000000");
strcpy_s(Maze[11], "00001000000100000000");
strcpy_s(Maze[12], "00011000000111111100");
strcpy_s(Maze[13], "00010000001100000100");
strcpy_s(Maze[14], "00011111000000001100");
strcpy_s(Maze[15], "00000001000000001000");
strcpy_s(Maze[16], "00011101000111111000");
strcpy_s(Maze[17], "00000101000000000000");
strcpy_s(Maze[18], "00000111111111111110");
strcpy_s(Maze[19], "00000000000000000030");
}
你不能,编译器不知道这些名称,你一定是遗漏了什么,也许你在main中包含了其他文件中的这些typedef,很难说,唯一可以确定的是,你单独显示的代码永远不会像你在中确认的那样编译
无论如何,C++中不需要为结构使用Type,可以声明结构如下:
struct POINT
{
int x;
int y;
};
使用它,不需要使用struct
关键字来声明变量o typePOINT
POINT tPlayerPos;
POINT tStartPos;
POINT tEndPos;
另一件需要注意的事情是,“overrided”可能不是您的意思,关键字有不同的含义
我也没有在您的代码中看到对
结构的任何重新定义。@Meggii,任何时候。