PDA

Click to See Complete Forum and Search --> : Passing Parameters


vb_dba
Nov 28th, 2001, 06:05 PM
I have the following struct definition:
typedef struct AppInfo{
string AppName;
string AppVer;
TCHAR pcName[256];
} strApp;

I am passing it to a function this way:
GetInfo(&strApp);

and my function is declared:
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.

Zaei
Nov 28th, 2001, 06:19 PM
Change

int GetInfo(strApp &AppList)


to


int GetInfo(strApp *AppList)


Z.

vb_dba
Nov 28th, 2001, 06:26 PM
Zaei:

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

Zaei
Nov 28th, 2001, 07:33 PM
Change this:

AppList.AppName = "Windows";


to

AppList->AppName = "Windows";


Z.

Wynd
Nov 28th, 2001, 07:37 PM
You should be able to do:int GetInfo(strApp &AppList)

GetInfo(strApp);

HarryW
Nov 28th, 2001, 07:57 PM
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.