[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ProgSoc] returning ptr to struct in c++ ?



Hi! I writing some C++ code. I have stuff this in the header:

////////////////////////////////////////
typedef struct _point
{   long   x;
    long   y;
} point;

typedef struct _obstacle
{
    point   tl;  // top left
    point   tr;  // top right
    point   bl;  // bottom left
    point   br;  // bottom right
} obstacle;

typedef struct _object
{
    obstacle * ob;
    int        ttl;
    int        type;
} object;

class geoff {
    public:
	object * cloneOb(const object * pSrc) const;
};
////////////////////////////////////////

And this stuff is in the .cpp file:

////////////////////////////////////////
object * geoff::cloneOb(const object * pSrc) const
{
    // alloacate space
    pNewOb = new object;
    pNewOb->ob = new obstacle;

    // fill it in
    pNewOb->ob->tl.x = pSrc->ob->tl.x; pNewOb->ob->tl.y = pSrc->ob->tl.y;
    pNewOb->ob->tr.x = pSrc->ob->tr.x; pNewOb->ob->tr.y = pSrc->ob->tr.y;
    pNewOb->ob->bl.x = pSrc->ob->bl.x; pNewOb->ob->bl.y = pSrc->ob->bl.y;
    pNewOb->ob->br.x = pSrc->ob->br.x; pNewOb->ob->br.y = pSrc->ob->br.y;
    pNewOb->type = pSrc->type;
    pNewOb->ttl = pSrc->ttl;

    return pNewOb;
}
//////////////////////////////////////// 

but I get a compiler error "Declaration syntax error" on the function
declaration in the .cpp file.

(There are, of course, other things in the files like constructors etc,
but they do not cause me problems :)

All help appreciated
Geoff


-
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@nospam.progsoc.uts.edu.au.
If you are having trouble, ask owner-progsoc@nospam.progsoc.uts.edu.au for help.