Appears to be Function Definition

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MarQade
    New Member
    • Oct 2007
    • 2

    Appears to be Function Definition

    Hi, I am new here. I am also a first-year computer science student looking for some help with a very small C++ program.
    This is a 3-file program, header file with declarations and 2 source files, one for definition and the other is the actual application file. I am attempting to write a non-member function.
    In my header file, I have declared bool isLarger(int x, int y); outside of the class. In my application file, before the end of the program, I have written the following code:
    [code=cpp]
    bool isLarger(firstD ate.convert(), secondDate.conv ert())
    {

    if (firstDate.conv ert() > secondDate.conv ert())
    {
    cout << "The first date entered is the most recent. " << endl << endl;
    return true;
    }
    else
    {
    cout << "The second date entered is the most recent. " << endl << endl;
    return false;
    }
    }
    [/code]
    When compiling this, the only error message I receive is: "error C2448: 'isLarger' : function-style initializer appears to be a function definition".

    I think that that is what I intended - a function definition. Is there something illegal about this code that I am just not seeing?

    Thank you in advance for any help.

    Michelle
    Last edited by sicarie; Oct 30 '07, 03:27 PM. Reason: Code tags
  • oler1s
    Recognized Expert Contributor
    • Aug 2007
    • 671

    #2
    bool isLarger(firstD ate.convert(), secondDate.conv ert())

    Mind telling us what that is supposed to be?

    Comment

    • MarQade
      New Member
      • Oct 2007
      • 2

      #3
      Sure. I'm calling the results of date conversions for the two separate objects of my CDate class - firstDate and secondDate. The point of this particular portion of this assignment is to compare the results of the convert method and cout which object is larger.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Originally posted by MarQade
        bool isLarger(firstD ate.convert(), secondDate.conv ert())
        {

        if (firstDate.conv ert() > secondDate.conv ert())
        {
        cout << "The first date entered is the most recent. " << endl << endl;
        return true;
        }
        else
        {
        cout << "The second date entered is the most recent. " << endl << endl;
        return false;
        }
        }
        You are confusing writing a function with calling a function. The compiler wants to know what the types of the arguments are and not where you are getting them from.

        The above is a function definiton, not a call.
        [code=cpp]
        bool isLarger(int, int) <<<<
        {
        //etc
        }
        [/code]

        Comment

        Working...