proper function call syntax

This is a discussion on proper function call syntax within the C++ Programming forums, part of the General Programming Boards category; What is the proper syntax for calling this function? Code: void BA747_RADIO::StoreThisMessage(B747_Flight::Flight_t flight, unsigned index) { int temp; Flight_Object flightObj; ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    77

    proper function call syntax

    What is the proper syntax for calling this function?

    Code:
    void BA747_RADIO::StoreThisMessage(B747_Flight::Flight_t flight, unsigned index)
    {
        int temp;
        Flight_Object flightObj;
    
           temp = (int)_data.msgsReceived[index].type;
            switch (temp) {
               case BA747_RADIO::VORTACS:
                    // vor/tacan
                    flightObj.Add_Radio_aid(radiodata.Rec[index].VORTAC_Data, flight);
                    break;
               case BA747_RADIO::ADFS:
                    // adf
                    flightObj.Add_Radio_aid(radiodata.Rec[index].ADF_Data, flight);
                    break;
            };              
    } // end BA747_RADIO::StoreThisMessage
    Last edited by jerrykelleyjr; 12-27-2004 at 07:30 PM.

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    It depends on the scope. If you're outside of the class you need to include the class name, and depending on how that object is reference, add the appropriate operator (-> for point, . for otherwise). You then have the function name, and include the parameters. To give you more detail on the parameters, you probably want to use a simpler example. I have no idea what this function does, and it's quite hard to tell. But if that's enough detail, then... [random smiley][/random smiler]

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Here is one way:

    Code:
    class_object.StoreThisMessage(B747_Flight_t_object , number);
    Last edited by The Brain; 12-27-2004 at 07:41 PM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    77
    OK...calling it from outside the class...what would the call look like? Also note that in my code example the "Flight_ t" should be "Flight_t"...probably obvious to most.
    Last edited by jerrykelleyjr; 12-27-2004 at 07:35 PM.

  5. #5
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Code:
    // Declare an instance of DA747_RADIO called Instance, a pointer to it called IPointer, and the data for the necessary parameters
     
    Instance.StoreThisMessage(my_flight, an_index);
    IPointer->StoreThisMessage(another_flight, one_index);

  6. #6
    Registered User
    Join Date
    Dec 2004
    Posts
    77
    Could I simply make the call like this?

    BA747_RADIO::StoreThisMessage(my_flight, an_index);

  7. #7
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    nope. you have to:

    1) declare an instance of the BA747_RADIO class:
    Code:
    BA747_RADIO *Boeing_Avionics;
    or
    Code:
    BA747_RADI Boeing_Avionics;

    2) dereference StoreThisMessage( ) from the newly created class object:
    Code:
    Boeing_Avionics->StoreThisMessage(argument1, argument2);
    or
    Code:
    Boeing_Avionics.StoreThisMessage(argument1, argument2);

    You get extra bonus points for asking a pilot
    Last edited by The Brain; 12-27-2004 at 08:07 PM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  8. #8
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Could I simply make the call like this?
    In some languages you can do that by making the class "static", but since I imagine that you want to "Store This Message" in a particular 747 Radio object, that would defeat the purpose.

  9. #9
    Registered User
    Join Date
    Dec 2004
    Posts
    77
    declaring an instance? hmmmm..What exactly does that do?

  10. #10
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    Ok, do me a favor and read this .

    After that why don't you tell us exactly what you are trying to do, maybe with some code/psuedocode.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

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, 07:54 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 12:45 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Question on function syntax and calling function
    By cbrman in forum C Programming
    Replies: 10
    Last Post: 10-05-2003, 06:32 PM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 11:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21