Odd structure

B

Bryan

I was looking through some old legacy code that has been a pain for some
time and I found this:

typedef struct MSObject {
// Members
} MSObject;

Why would you do this? And furthermore, why, if I change it to:

class MSObject {
public:
// Members
};

do all the functions that use MSObject complain of a syntax error ')'
when I try to compile?

I would really like to replace this typedef'ed type with an object
without having to modify all the files (and there are a bunch) that use it.
 
M

mlimber

Bryan said:
I was looking through some old legacy code that has been a pain for some
time and I found this:

typedef struct MSObject {
// Members
} MSObject;

Why would you do this? And furthermore, why, if I change it to:

class MSObject {
public:
// Members
};

do all the functions that use MSObject complain of a syntax error ')'
when I try to compile?

I would really like to replace this typedef'ed type with an object
without having to modify all the files (and there are a bunch) that use it.

The original code with that typedef business was likely written to be
compatible with C or was written by someone unfamiliar with C++'s
changes. The first "MSObject" is the struct tag, and the second is a
the typedef name (i.e., an alias for "struct MSObject"). In C++, the
"typedef" and second "MSObject" are unnecessary, but even without them,
it can still be used as either "struct MSObject" or just "MSObject".

As for your syntax error, post a *complete* but *minimal* sample that
demonstrates the problem, and we can tell you.

Cheers! --M
 
R

Rolf Magnus

Bryan said:
I was looking through some old legacy code that has been a pain for some
time and I found this:

typedef struct MSObject {
// Members
} MSObject;

Why would you do this?

Do what?
And furthermore, why, if I change it to:

class MSObject {
public:
// Members
};

do all the functions that use MSObject complain of a syntax error ')'
when I try to compile?

Hard to tell without any more code. Maybe the functions have
'struct MSObject' as parameter?
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top