Thread: 'Local Function Definitions are illegal' ?

  1. #1
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218

    'Local Function Definitions are illegal' ?

    this is my code:

    Code:
    void Cat::Eat()
    {
    	printf("\n%s ate.", name);
    }
    // ... other functions with same error
    and this is my error:
    "Local Function Definitions are illegal."

    What does that mean?

    I'm using MSVC++7.

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Make sure you didn't leave out a closing brace. Otherwise, post some more code, please.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218

    Nevermind!

    I fixed THAT problem. I have another one, however. It happens somewhere in here:

    Code:
    int main()
    {
    	// get name & set
    	printf("What is the cat's name? ");
    	scanf("%s",cat.name);
    
    	// get age & set
    	printf("\nWhat is the cat's age? ");
    	scanf("%i",cat.age);
    
    	// get weight & set
    	printf("\nWhat is the cat's weight? ");
    	scanf("&i",cat.weight);
    
    	//printf("\nNAME: %s",cat.GetName());
    	printf("\nAGE : %i",cat.age);
    
    	return 0;
    }
    the program crashes when I input the age. The age is an int.

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Why are you using scanf/printf with C++? You should be using cin/cout.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    try using %d instead of %i
    I came up with a cool phrase to put down here, but i forgot it...

  6. #6
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218

    I/O

    I solved the input problem using "cin".

    However, although I like C++ input (cin), I like C output (printf,etc.). It doesn't really matter, does it?

    printf() is slightly faster, anyways.

  7. #7
    Registered User
    Join Date
    Aug 2003
    Posts
    51
    what XSquared said.

    But as for y it's crashing, i'd say because u need to pass cat.age's address.

    scanf takes the address of an object, so

    Code:
    scanf("%i",&(cat.age));
    it doesn't crash on cat.name (assuming name is a string) because when using an identifier for an array it passes the address of the first element.

  8. #8
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218
    That's right, Kyro! Darn! I always forget that scanf takes the adress. Silly me.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. local function definitions are illegal
    By curlious in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2003, 04:09 AM