passing by value pointer of a struct

Discussion in 'C++' started by irvin.hwang@gmail.com, May 15, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, May 15, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Fogelklou
    Replies:
    36
    Views:
    1,433
    Chris Fogelklou
    Apr 20, 2004
  2. beetle
    Replies:
    2
    Views:
    946
    beetle
    Jan 25, 2005
  3. Zero
    Replies:
    16
    Views:
    675
    Barry Schwarz
    Nov 19, 2005
  4. jimjim
    Replies:
    16
    Views:
    861
    Jordan Abel
    Mar 28, 2006
  5. aleksa

    Struct pointer vs. struct array pointer

    aleksa, Feb 20, 2013, in forum: C Programming
    Replies:
    16
    Views:
    499
    Shao Miller
    Feb 20, 2013
Loading...

Share This Page