Thread: Weird problem: error C2017: illegal escape sequence

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485

    Weird problem: error C2017: illegal escape sequence

    I just started using Visual C++, and I have an error that I cant understand why I get.
    The error message I get is: error C2017: illegal escape sequence

    I looked it up, and normally you get that error if you do something wrong with a string/char, but i dont have a single string or char in my program, and certainly not in the line its complaining about.

    Its in the first line in code posted the error is.

    Code:
    void Cube::draw()
    {
    	// Find the top corner of the cube we are about to draw
    	int x = xPos - (size / 2);
    	int y = yPos - (size / 2);
    
    	for (int i = x; i < scale; i++)
    	{
    		for (int j = y; j < scale; j++)
    		{
    			int pixelOffset = BYTES_PER_PIXEL * ((i *  SCREEN_WIDTH) + j);
    
    			screen[pixelOffset] = 255;
    		}
    	}
    }
    Thanks for your time

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Have a look JUST BEFORE where you are - errors quite often get "linenumber" from the line that the compiler discovers that "Huh - this isn't what I expected here", which means that a missing semicolon or whatever on a line ABOVE could be the cause.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Thanks for the reply.

    I fooled around with the code a bit and the error changed into something else. The problem was that "size" also was a name for one of the class functions.

    Still having problems with understanding why I got the first error, I probably did something random somewhere. Fixed now

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I wonder if that was the first error message you got and there was no mention of the name conflict? If so you should always deal with the first error you get because the others may just result from it.

    If I understand you correctly your problem looked somewhat like that?
    Code:
    struct Foo
    {
        int size() const;
        int size;    
    };
    
    
    int main()
    {
        Foo f;
        int i = f.size();
    }
    
    int Foo::size() const
    {
        return 42;
    }
    For example Comeau online says:
    "ComeauTest.c", line 4: error: "size" has already been declared in the current scope
    int size;
    ^

    "ComeauTest.c", line 11: error: expression must have (pointer-to-) function type
    int i = f.size();
    ^

    "ComeauTest.c", line 11: warning: variable "f" is used before its value is set
    int i = f.size();
    ^

    "ComeauTest.c", line 14: error: declaration is incompatible with "int Foo::size"
    (declared at line 4)
    (You could sometimes "ask" a different compiler's opinion, but you might probably get more comfortable with the messages of your compiler so you won't need to. Also note that the messages concerning line 11 don't make any sense at all if you just look at main.)
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    anon: Thats basically what I had, just with the random error.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird Problem With Pointer
    By DarkDot in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2007, 07:50 PM
  2. Weird problem with sscanf
    By g4j31a5 in forum C++ Programming
    Replies: 17
    Last Post: 10-04-2006, 09:16 PM
  3. weird problem!
    By spank in forum C Programming
    Replies: 2
    Last Post: 04-08-2006, 03:26 AM
  4. weird problem with passing a value..
    By Unregistered in forum C Programming
    Replies: 11
    Last Post: 06-21-2002, 09:05 AM
  5. Weird (stupid?) Problem: error C2448: '<Unknown>'
    By Dual in forum C++ Programming
    Replies: 3
    Last Post: 12-08-2001, 03:28 AM