C Structure Inheritance

S

sri

Dear All,

I am trying to inherit C Structure interface and its implementation
developed by third party. I would like to provide a wrapper kind of
class to my user. For instance,

mapctx.h
-------------

struct MAPCTX
{
......
}

mapctx.c
-------------
void InitMapctx(long xsize)
{
xsize = 7;
}

MyCpp.h
-------------
class MyMapCtx : public MAPCTX
{
void XInitMapContext(long XSize)
{
InitMapctx(XSize);
}
};

When I compile this code in Microsoft C++ compiler it is giving the
following errors

error C2143: syntax error : missing ')' before 'constant'
error C2143: syntax error : missing ';' before 'constant'
error C2059: syntax error : 'constant'
error C2059: syntax error : ')'
error C2334: unexpected token(s) preceding '{'; skipping apparent
function body

As per my observation parameter XSize is causing to list these errors.
Please let me know why this is going wrong.

With Regards,
Sri
 
S

sri

I noticed the cause, the problem is XSize is already defined as a
constant in the third party library.

With Regards,
Sri
 
V

Victor Bazarov

sri said:
I am trying to inherit C Structure interface and its implementation
developed by third party. I would like to provide a wrapper kind of
class to my user. For instance,

mapctx.h
-------------

struct MAPCTX
{
.....
}

A semicolon is missing here.
mapctx.c
-------------
void InitMapctx(long xsize)
{
xsize = 7;
}

This function has no effect whatsoever. A good link-based optimizer
is likely to take it out completely.

To give this function the desired effect, pass the arg by reference.
MyCpp.h
-------------
class MyMapCtx : public MAPCTX
{
void XInitMapContext(long XSize)
{
InitMapctx(XSize);
}

This member function has no effect either. Same comment as above.
};

When I compile this code in Microsoft C++ compiler it is giving the
following errors

error C2143: syntax error : missing ')' before 'constant'

On which line?
error C2143: syntax error : missing ';' before 'constant'

Again, on which line?
error C2059: syntax error : 'constant'
error C2059: syntax error : ')'
error C2334: unexpected token(s) preceding '{'; skipping apparent
function body

As per my observation parameter XSize is causing to list these errors.
Please let me know why this is going wrong.

Could it be that 'XSize' is actually a type name? What if you changed
the name of the argument in the 'XInitMapContext' member?

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top