Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > passing by value pointer of a struct

Reply
Thread Tools

passing by value pointer of a struct

 
 
irvin.hwang@gmail.com
Guest
Posts: n/a
 
      05-15-2006
Hi,

I'm having a problem passing a pointer of a struct. Here is the code
that's giving me a trouble.

1. shape *s;
2. s = load_shape();
3. shape2grammar(s);

test.cpp:53: error: no matching function for call to
'shape2grammar(shape*&)'

This is the declaration of shape2grammar...it takes a pointer to shape
as an argument
prod_rule<T>* shape2grammar(shape* s)

Shape is a struct...
struct shape {
location *v;
int num;
matrix<bool> *edges; // adjencency matrix for triangulation
};

and load_shape() returns a pointer to a shape
shape *load_shape()

It appears the program thinks line '3. shape2grammar(s)' is a call
where s is a pointer to the address of a shape (when I tried replacing
this with '3. shape2grammar(*s)' i get the error "no matching function
for call to 'shape2grammar(shape&)'")

but it's clear that what is returned by '2.s = load_shape()' is a
pointer to a shape because I tried accessing the members of s before
the call '3. shape2grammar(s)' (i.e. 's->num' works) and it seemed
fine.

Any suggestions would be appreciated.

Thanks,
Irvin H.

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      05-15-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> I'm having a problem passing a pointer of a struct. Here is the code
> that's giving me a trouble.
>
> 1. shape *s;
> 2. s = load_shape();
> 3. shape2grammar(s);
>
> test.cpp:53: error: no matching function for call to
> 'shape2grammar(shape*&)'
>
> This is the declaration of shape2grammar...it takes a pointer to shape
> as an argument
> prod_rule<T>* shape2grammar(shape* s)
>
> Shape is a struct...
> struct shape {
> location *v;
> int num;
> matrix<bool> *edges; // adjencency matrix for triangulation
> };
>
> and load_shape() returns a pointer to a shape
> shape *load_shape()
>
> It appears the program thinks line '3. shape2grammar(s)' is a call
> where s is a pointer to the address of a shape (when I tried replacing
> this with '3. shape2grammar(*s)' i get the error "no matching
> function for call to 'shape2grammar(shape&)'")
>
> but it's clear that what is returned by '2.s = load_shape()' is a
> pointer to a shape because I tried accessing the members of s before
> the call '3. shape2grammar(s)' (i.e. 's->num' works) and it seemed
> fine.


The 'shape2grammar' declaration must exist before you attempt to call it.

> Any suggestions would be appreciated.



Read FAQ 5.8 and follow its recommendations.

V
--
Please remove capital As from my address when replying by mail


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Struct pointer vs. struct array pointer aleksa C Programming 16 02-20-2013 08:20 PM
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
(: Pointer to struct withing pointer to struct :) Zero C Programming 16 11-19-2005 01:27 AM
passing pointer->struct->pointer->struct to function. .. ?? beetle C Programming 2 01-25-2005 06:08 PM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM



Advertisments