Thread: Illegal local function definition

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    26

    Illegal local function definition

    Can you point out my error? Am I missing something obvious???

    The function should return a TRUE if the number falls between -9999 and +9999. False if out of range.

    Using MSV C++ 6 Intro edition found in Dietel & Dietel

    bool validword(int); // declaration


    if ( !validword( temp ) ) // call out

    bool validword(int word) // function
    {
    return ( word >= -9999 && word <= 9999 );
    // word must be 4 digits max (+ or -)
    }


    error message:
    error C2601: 'validword' : local function definitions are illegal

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Your missing a } somewhere. Probably in the function that is defined directly above the function in which you're getting the error. The error is basically saying you can't have nested functions in C/C++. Since you still have an open ended function somewhere, that's what it seems like you're trying to do.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    20

    Re: Illegal local function definition

    It would be easier to spot the problem if you included main(), but meanwhile, what's:

    if ( !validword( temp ) ) //??????????????
    bool validword(int word)
    {
    return ( word >= -9999 && word <= 9999 );
    }
    Al

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >if ( !validword( temp ) )
    This is the call to the validword function. validword only returns true or false, so !validword(temp) takes temp as the argument and if it returns true (non-zero) then the condition is met, otherwise the if statement is skipped because the function returned false (zero). Another way to write this would be
    if((validword(temp)) != 0)

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Local function definitions are illegal error?
    By GrlNewB in forum C++ Programming
    Replies: 3
    Last Post: 04-10-2003, 08:54 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM