Mail Archives: djgpp/1999/11/05/21:12:01
On 5 Nov 99, at 19:26, Philip Bock <philipb AT escape DOT ca> wrote:
> I have a function whose definition looks like this: (vimg is a struct)
>
> void draw_vimg(vimg vectimg, int x, int y, int xscale, int yscale);
>
> I want to pass it a vimg defined like so: (gen_vimg creates and sets initail
> values for the struct)
>
> vimg *mygraphic;
> mygraphic = gen_vimg();
>
> So I call draw_vimg like this:
>
> draw_vimg(mygraphic, 200, 100, 1, 1);
>
> And I get errors like this:
>
> vector.cpp: In function `int main()':
> vector.cpp:45: conversion from `vimg *' to non-scalar type `vimg'
> requested
>
> So what can I do to send pointers to functions that call for variables, and
> not pointers too the variables?
Greetings Phillip,
You normally do not pass structures to functions (if the structure
is large it will be very ineficient as a copy of it has to be made)
instead you pass pointers to them.
So I think that your function definition should be,
void draw_vimg(vimg * vectimg, int x, int y, int xscale, int yscale);
I put a "*" (star) before vectimg to say that vectimg will be passed
as a pointer. So if vimg has a member called x,within the functn
you would acess it as vectimg->x .
So I think you should rewrite draw_vimg to accept pointer's to
structs.
However if you still want to use your function definition, the problem
you are having is that mygraphic is a pointer ( vimg *mygraphic).
And although your functn drawimage wants a structure (not a
pointer) as it's first argument you are attempting to pass a pointer(
mygraphic) to it and the compiler says that it can't convert
mygraphic which is type vimg *(pointer) to vimg (structure).
So If you want to pass mygraphic(a pointer) as a structure you
would put a star "*" in front of mygraphic. example-:
draw_vimg( *mygraphic, 200, 100, 1, 1);
A quick summary -: If you have structure (struct img;) and you
want to get a pointer to it you would use "&img" (without the
quotes). If you have a pointer (vimg * mygraphic) and you want to
pass it as a structure you would use "*mygraphic"(put a asterik
infront of it).
Hope this help's you my friend!
Kalum.
- Raw text -