visual-studio-2012 - 奇怪的名字混淆

标签 visual-studio-2012 clr

我有以下迷你游戏代码(用 CLR 编写,不值得完整阅读):

#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
using namespace System;
char map[15][15+1]={
    "###############",
    "#.............#",
    "#.............#",
    "#....#####....#",
    "#.............#",
    "#.............#",
    "#.............#",
    "######...######",
    "#.............#",
    "#.............#",
    "#.............#",
    "#....#####....#",
    "#.............#",
    "#.............#",
    "###############"};
int x1,y1,x2,y2;
int val(int x, int y){
    if(map[y][x]=='#') return 0;
    if(x==x1 && y==y1) return 0;
    if(x==x2 && y==y2) return 0;
    return 1;
}
int main(array<System::String ^> ^args)
{
    int x, y;
    while(1){
        cin>>x>>y;
        if(x<0 || x>=15 || y<0 || y>=15 || map[y][x]=='#')
            continue;
        break;
    }
    while(1){
        cin>>x1>>y1;
        if(x1<0 || x1>=15 || y1<0 || y1>=15 || map[y1][x1]=='#')
            continue;
        break;
    }
    while(1){
        cin>>x2>>y2;
        if(x2<0 || x2>=15 || y2<0 || y2>=15 || map[y2][x2]=='#')
            continue;
        break;
    }
    system("cls");
    for(int i=0;i<15;++i) cout<<map[i]<<endl;
    int d1=1,d2=1,choq=0;
    while(1){
        Sleep(100);
        Console::SetCursorPosition(x,y);
        cout<<".";
        if(_kbhit()){
            int dir=_getch();
            if(dir==72){//ar
                if(val(x,y-1)) y-=1;
                else ++choq;
            }
            if(dir==75){//izq
                if(val(x-1,y)) x-=1;
                else ++choq;
            }
            if(dir==77){//der
                if(val(x+1,y)) x+=1;
                else ++choq;
            }
            if(dir==80){//ab
                if(val(x,y+1)) y+=1;
                else ++choq;
            }
            if(dir=='s' || dir=='S')
                break;
        }
        Console::SetCursorPosition(x1,y1);
        cout<<".";
        Console::SetCursorPosition(x2,y2);
        cout<<".";
        if(map[y1+d1][x1]=='#' || (y1+d1==y && x1==x)){
            if(y1+d1==y && x1==x)++choq;
            d1=-d1;
        }
        if(map[y2+d2][x2]=='#' || (y2+d2==y && x2==x)){
            if(y2+d2==y && x2==x)++choq;
            d2=-d2;
        }
        y1+=d1;
        y2+=d2;
        Console::SetCursorPosition(x1,y1);
        cout<<"#";
        Console::SetCursorPosition(x2,y2);
        cout<<"#";
        Console::SetCursorPosition(x,y);
        cout<<"#";
        Console::SetCursorPosition(0,16);
        cout<<choq <<" choques.";
    }
    Console::SetCursorPosition(0,17);
    cout<<"Simulacion terminada.";
    getchar();
    getchar();
    return 0;
}

但是当我编译时,我收到错误消息,指出 x1, y1 的类型为 double (_cdecl*)(double)。如果我用 x_1, y_1 替换它们的名字,问题就解决了。但是,为什么会出现这种情况呢?我在包含的 header 中的任何位置都找不到该定义,并且当我编写 x1( 时,intelliSense 不会提示我有关参数或类型的信息。此外,Visual Studio 2012 不会提示该行

int x1,y1,x2,y2;

重新定义。

你可以帮助我理解这种行为吗?

最佳答案

它们已被弃用 Posix functions 。您从 <math.h> 获取它们,被 <iostream> 拉入.

您找到的解决方法还可以。这些名称选择来自程序员必须用左脚操作 Shift 键的时代,计算机仍在与桌面计算器竞争,并且在全局命名空间中转储短标识符名称并不像今天那么严重。像“y1”这样的标识符名称适合参数或局部变量名称。

对于全局变量来说不太好。对全局变量使用描述性名称,您仍然只需按几个键。编辑器的自动完成功能是您的 friend 。代码的读者和编译器都会感谢您。

关于visual-studio-2012 - 奇怪的名字混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24578870/

相关文章:

asp.net - Web 应用程序中的 CLR 触发器?

.net - CLR安装在哪里?

visual-studio-2012 - 编辑和保存文本文件始终显示“另存为”对话框

c# - 如何为多个 Visual Studio 版本打包基于 VSIX 的扩展?

.net - 调用执行程序时发生异常 'executor://mstestadapter/v1' : Type is not resolved for member

visual-studio-2012 - 类文件在 Visual Studio 2011 中不可见

c++ - Windows 上的 DLL 项目 : Unresolved External Symbol

c# - 静态通用类作为字典

c# - 我如何识别代表 SZ-Array 的 System.Type 实例?

c# - IL 知道什么是接口(interface)吗?