cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/05/21:12:01

From: "Kalum Somaratna aka Grendel" <kalum AT ToughGuy DOT net>
To: djgpp AT delorie DOT com
Date: Sat, 6 Nov 1999 06:28:29 +0600
MIME-Version: 1.0
Subject: Re: Pointers passed to functions
Cc: philipb AT escape DOT ca
In-reply-to: <4cGU3.2300$1J5.254437@typhoon.mbnet.mb.ca>
X-mailer: Pegasus Mail for Win32 (v3.12)
Message-Id: <19991106002850.79496639CB@zagnut.hotpop.com>
X-HotPOP: -----------------------------------------------
Sent By HotPOP.com FREE Email
Get your FREE POP email at www.HotPOP.com
-----------------------------------------------
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019