-
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:
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.
-
Change
Code:
int GetInfo(strApp &AppList)
to
Code:
int GetInfo(strApp *AppList)
Z.
-
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.
-
Change this:
Code:
AppList.AppName = "Windows";
to
Code:
AppList->AppName = "Windows";
Z.
-
You should be able to do:
Code:
int GetInfo(strApp &AppList)
GetInfo(strApp);
-
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.