Results 1 to 6 of 6

Thread: Passing Parameters

  1. #1

    Thread Starter
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016

    Passing Parameters

    I have the following struct definition:
    Code:
     typedef struct AppInfo{
      string AppName;
      string AppVer;
      TCHAR pcName[256];
    } strApp;
    I am passing it to a function this way:
    Code:
    GetInfo(&strApp);
    and my function is declared:
    Code:
    int GetInfo(strApp &AppList)
    when I compile, I get an error message stating that the function GetInfo can't convert parameter 1 from strApp * to strApp &. It's been a couple of years since I've programmed in C++ (does it show?). I want to be able to view the new contents of AppList outside of the GetInfo function. I know this is newbie question, but I'd appreciate your help.
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  2. #2
    Zaei
    Guest
    Change
    Code:
    int GetInfo(strApp &AppList)
    to

    Code:
    int GetInfo(strApp *AppList)
    Z.

  3. #3

    Thread Starter
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    Zaei:

    I changed the function definition to:
    Code:
    void GetInfo(AppInfo *AppList)
    and that resolved the error above. I'm now getting the following error:
    Code:
    error C2228: left of '.appname' must have class/struct/union type
    The line where I'm getting the error is this:
    Code:
    AppList.AppName = "Windows";
    This is inside the GetInfo function.
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  4. #4
    Zaei
    Guest
    Change this:
    Code:
    AppList.AppName = "Windows";
    to
    Code:
    AppList->AppName = "Windows";
    Z.

  5. #5
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    You should be able to do:
    Code:
    int GetInfo(strApp &AppList)
    
    GetInfo(strApp);
    Alcohol & calculus don't mix.
    Never drink & derive.

  6. #6
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Just do what Wynd suggests and use a reference instead of a pointer.

    The original problem was that you were declaring the function as taking a reference to a strApp, and you were instead passing it the address of a strApp. You should just pass the strApp object into the function, not a pointer to it.

    If you use a reference, you don't have to worry about dereferencing the pointer every time you want to use it. You can leave your code just as it was before.

    So change your code back to how you had it, and then do what Wynd suggested.
    Harry.

    "From one thing, know ten thousand things."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width