Thread: Strange compiling problem

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    18

    Strange compiling problem

    For some reason these 2 functions (which I copied from another program of mine that compiles fine) give me this error:

    Code:
    C:\Program Files\Microsoft Visual Studio\MyProjects\SnSCheckers\main.cpp(138) : error C2601: 'getxcoord' : local function definitions are illegal
    C:\Program Files\Microsoft Visual Studio\MyProjects\SnSCheckers\main.cpp(174) : error C2601: 'getycoord' : local function definitions are illegal
    which results in
    Code:
    C:\Program Files\Microsoft Visual Studio\MyProjects\SnSCheckers\main.cpp(187) : fatal error C1004: unexpected end of file found
    Here's my prototypes of the 2 functions:
    Code:
    int getxcoord(void);
    int getycoord(void);
    Here's where I use them (so far):
    Code:
    xposition = getxcoord();
    yposition = getycoord();
    Here's the functions themselves:
    Code:
    int getxcoord(void)
    {
    	char letter;
    	int x = 9;
    
    	cout << "A - H: ";
    	
    	while(x == 9)
    	{
    		cin >> letter;
    		letter = toupper(letter);
    		switch (letter)
    		{
    			case 'A':	x = 1;
    					break;
    			case 'B':	x = 2;
    					break;
    			case 'C':	x = 3;
    					break;
    			case 'D':	x = 4;
    					break;
    			case 'E':	x = 5;
    					break;
    			case 'F':	x = 6;
    					break;
    			case 'G':	x = 7;
    					break;
    			case 'H':	x = 8;
    					break;
    			default :	cout << "Please give a letter from A to H: ";
    		}
    	}
    
    	return(x);
    }
    
    int getycoord(void)
    {
    	int y = 9;
    
    	cout << "1 - 8: ";
    	cin >> y;	
    	while(y < 1 || y > 8)
    	{
    		cout << "Please give a number from 1 to 8: ";
    		cin >> y;
    	}
    
    	return(y);
    }
    anyone know what's wrong?

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    that error usually comes up when you have a bracket out of place somewhere. Those ones look fine, but check main().

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Look for a missing brace in the function which precedes those functions.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    18
    couldn't find anything...

    was it a brace or a bracket that would be missing?

  5. #5
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Quote Originally Posted by SnS CEO
    couldn't find anything...

    was it a brace or a bracket that would be missing?
    One of these }

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    18
    well, it gives me the error on the first { of those 2 functions:

    Code:
    int getxcoord(void)
    {                                        //The error it gives is on this line
    	char letter;
    	int x = 9;
    .
    .
    .
    Code:
    int getycoord(void)
    {                                   //And on this one
    	int y = 9;
    
    	cout << "1 - 8: ";
    .
    .
    .
    couldn't find any "{" or "}" that were outa place. ill keep searching (its not that big of a program yet).

  7. #7
    *this
    Join Date
    Mar 2005
    Posts
    498
    Can we see main() that calls these functions?

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Would sure be easier if you posted what you're trying to compile.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Aug 2005
    Posts
    18
    [DELETE]

    I found it
    Last edited by SnS CEO; 08-07-2005 at 04:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem compiling files that store functions
    By tiachopvutru in forum C++ Programming
    Replies: 10
    Last Post: 05-30-2008, 05:42 PM
  2. Problem compiling simple code examples
    By Wintersun in forum Windows Programming
    Replies: 8
    Last Post: 08-14-2007, 10:30 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. Problem Compiling
    By Flakster in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 01:09 AM
  5. bcc32 compiling error (really strange!!)
    By jester in forum C++ Programming
    Replies: 14
    Last Post: 01-26-2002, 04:00 PM