Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

code behaviour is strange

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;
                };
        }
    }
like image 772
sparkling_spark Avatar asked Nov 23 '25 19:11

sparkling_spark


2 Answers

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.)

like image 175
James Kanze Avatar answered Nov 26 '25 08:11

James Kanze


The error complaining about the 0xa0 character, and the following semi-colon error are, I believe, both caused by a character that got accidentally copied into your code, which is a unicode character that you can't see, but just because you can't see it doesn't mean it's not there and wreaking havoc!

like image 34
prelic Avatar answered Nov 26 '25 08:11

prelic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!