'C' question
- From: Robby <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 18 Mar 2006 22:19:26 -0800
Hi,
I have experimented with passing an array of POINT structures to a function.
I did this like this:
First I declare my function:
void f(POINT[]);
Then I innitialized the array as so:
POINT ptsBase[6] = {40,265, 130,265, 80,265, 80,60, 200,60, 200,85};
then I call my function passing the array of structures as so:
f(ptsBase);
and the function its self is written as so:
void f(POINT ptsBase[])
{ //some code}
This works fine and is no problem.
However, I am now trying to pass an array of structures to a function where
the structure is one that I created, but this doesn't work the same way since
it generates an error. I have never done this before. Here is my atempt:
Structure that I created/declared
================================
struct
{
int RNumber;
TCHAR *szRName;
}
RIndex[] =
{
1 ,TEXT("RedRail"),
2 ,TEXT("BlueRail"),
3 ,TEXT("GreenRail"),
4 ,TEXT("BlackRail #1"),
5 ,TEXT("BlackRail #2"),
6 ,TEXT("WhiteRail")
};
Here is the calling the function where I would like to pass it the array of
structures that I created
-------------------------------
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
f(RoomIndex);
EndPaint(hwnd,&ps);
return 0;
---------------------------------
//My function
void f(struct RoomIndex[])
{
//some code...
}
==============================
This gives me the following error,
c:\_DTS_PROGRAMMING\vc++\MY_APPS_LAB\APPLICATION_1\APPLICATION_1.cpp(227) :
error C2664: 'RL1_txtDISPLAY_GB_ArSt2ic' : cannot convert parameter 1 from
'[6]' to 'RoomIndex []' Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
I wish someone can help me understand what I am doing wrong. Its seems to
have something to do with casts, but I have never casted anything under this
context. I have looked for examples in books but unfortunately don't seem to
find any, the only documentation I have found is on structure basics,
pointers to structures, nested structures, understanding bit fields and
create unions, but nothing on passing an array of structures which the
programmer would create as done so in my sample.
All suggestions and help is very appreciated....
Thankyou guys!
--
Best regards
Robert
.
- Follow-Ups:
- Re: 'C' question
- From: Bruno van Dooren
- Re: 'C' question
- Prev by Date: InitInstance and exiting application
- Next by Date: Re: InitInstance and exiting application
- Previous by thread: InitInstance and exiting application
- Next by thread: Re: 'C' question
- Index(es):
Relevant Pages
|