473,320 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

passing by value pointer of a struct

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.

May 15 '06 #1
1 1692
ir*********@gmail.com 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
May 15 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: kazack | last post by:
I am a little confused with code I am looking at. My c++ book does not go into passing a structure to a function so I pulled out a c book which does. and I do not understand the prototype verses...
5
by: Andy | last post by:
Hi Could someone clarify for me the method parameter passing concept? As I understand it, if you pass a variable without the "ref" syntax then it gets passed as a copy. If you pass a...
4
by: Pushkar Pradhan | last post by:
I need to pass a struct by reference to a function: The struct: typedef struct tifftags { uint32 imageWidth, ...; ... } TIFFTAGS; typedef TIFFTAGS * TIFFTAGS_PTR; main() { .....
9
by: Just Me | last post by:
PARAFORMAT2 is a structure that SendMessage will return stuff in. Is the "ref" correct or since only a pointer is being passed should it be by value? Suppose I was passing data rather then...
17
by: Christopher Benson-Manica | last post by:
Does the following program exhibit undefined behavior? Specifically, does passing a struct by value cause undefined behavior if that struct has as a member a pointer that has been passed to...
2
by: jconnort | last post by:
I'm trying to write a function to get the current system time, so I can use it when I need to output it to a log, below is the code I'm testing: #include "include.h" #include <stdlib.h> ...
12
by: Mike | last post by:
Consider the following code: """ struct person { char *name; int age; }; typedef struct person* StructType;
6
by: Roman Mashak | last post by:
Hello, I belive the reason of problem is simple, but can't figure out. This is piece of code: struct timeval { long tv_sec; /* seconds */ long tv_usec; /* microseconds */ };
3
by: iskeletor | last post by:
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #define STUDENT_NUMBER 68 #define ARRAY_LENGTH 10 struct node{ char Name,Surname; int data,no;
8
by: S. | last post by:
Hi all, Can someone please help me with this? I have the following struct: typedef struct { char *name; int age; } Student;
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.