passing by value pointer of a struct

I

irvin.hwang

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.
 
V

Victor Bazarov

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top