|
-
Nov 28th, 2001, 07:05 PM
#1
Thread Starter
Fanatic Member
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.
Chris
Master Of My Domain
Got A Question? Look Here First
-
Nov 28th, 2001, 07:19 PM
#2
Change
Code:
int GetInfo(strApp &AppList)
to
Code:
int GetInfo(strApp *AppList)
Z.
-
Nov 28th, 2001, 07:26 PM
#3
Thread Starter
Fanatic Member
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
-
Nov 28th, 2001, 08:33 PM
#4
Change this:
Code:
AppList.AppName = "Windows";
to
Code:
AppList->AppName = "Windows";
Z.
-
Nov 28th, 2001, 08:37 PM
#5
Fanatic Member
You should be able to do:
Code:
int GetInfo(strApp &AppList)
GetInfo(strApp);
Alcohol & calculus don't mix.
Never drink & derive.
-
Nov 28th, 2001, 08:57 PM
#6
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|