代码行为很奇怪 [英] code behaviour is strange

查看:120
本文介绍了代码行为很奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从C#
切换到C ++,我用C ++编写了一个链接列表代码,并在win32控制台应用程序中运行它,并且在构建时出现了非常奇怪的错误

我指出了注释中的3个错误,其余的我都无法输入,太多了。

 使用命名空间std; 

float_list
{
结构节点
{
double data;
结构节点* next;
};
节点* head;
public:

float_list(void)
{
head = nullptr;
};

void appendNode(double);

};
// void float_list :: appendNode(float num)
// {
//
//}
void float_list :: appendNode(double num)
{
节点* newNode;
节点* ptr; //这里我收到此错误错误C3872:
// 0xa0:标识符
中不允许使用此字符//我一次又一次更改其名称。

newNode =新节点;
newNode-> data = num; //这里是未声明的标识符,
//也丢失了;在此行之前
newNode-> next = nullptr;


if(!head)
{
head = newNode;
}
其他
{
ptr =头;

而(ptr-> next)
{
ptr = ptr-> next;
ptr-> next = newNode;
};
}
}


解决方案

问题可能不是标识符,而是标识符周围的空白
0xA0 是不间断
空间的Latin-1代码。它不是输入中的合法字符,由于某种原因,
编译器将其视为标识符的一部分。如果没有其他效果,请删除该行并重新输入该行,确保所有空格均为普通空格。 (我不确定在Windows下是什么,但我认为控制空间或移位空间会进入不间断的空间。)


I just switched to C++ from C# I wrote a link list code in C++ ran it in win32 console application and getting very strange errors while build

I pointed out 3 errors in comments , rest I cant type ,its too much .

using namespace std;

class float_list
{
     struct node
    {
        double data;
        struct node *next;
     };
        node *head;
public:

    float_list(void)
    {
        head = nullptr;
    };

    void appendNode(double);

};
//void float_list::appendNode(float num)
//{
//      
//}
void float_list::appendNode(double num)
    {
        node *newNode; 
        node *ptr; //here i am getting this Error error C3872:
                       //'0xa0': this character is not allowed in an identifier  , 
                       // how ever I changed its name again and again.  

        newNode = new node;
        newNode->data = num; // here un declared identifier ,
                         //also missing ; before this line 
        newNode->next = nullptr;


    if (!head)
    {       
        head = newNode;
    }
    else 
    {       
                ptr = head;     

                while (ptr->next)
                {
                ptr = ptr->next;
                ptr->next = newNode;
                };
        }
    }

解决方案

The problem probably isn't the identifier, but the white space around it. 0xA0 is the Latin-1 code for a non-breaking space. It's not a legal character in input, and for some reason, the compiler is treating it as part of the identifier. If nothing else works, delete the line and reenter it, making sure that all spaces are normal spaces. (I'm not sure under Windows, but I think a control-space or a shift-space will enter the nonbreaking space.)

这篇关于代码行为很奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆