Odd structure question reformulated

B

Bryan

Okay, in some legacy code, in the .h file I have exactly this:
typedef struct MSObject
{
// this refers to the entire set of data points
double *x;
double *y;
int numValues;
// save zoomed values
double xval_start; // x[first] value in zoom window
double xval_end; // x[last] value in zoom window
int xyindex_start; // first x[index_start] in zoom window
int xyindex_end; // last x[index_end] in zoom window
double Ymin, Ymax; // within zoom window

}MSSpectrum;


// prototypes
int MSObjectReadXY(char *path, MSObject *object);

These are global, and any .c files that include this .h file and use the
MSObject contain also only global functions.

I reallllly want just to add a constructor and destructor to MSObject,
and not have to change the signature of every function that uses this
object.

I have tried every combination of classes, structs, typedefs and
otherwise but nothing will compile that will allow me to add a
constructor to this thing.

What do I need to do?
 
M

mlimber

Bryan said:
Okay, in some legacy code, in the .h file I have exactly this:
typedef struct MSObject
{
// this refers to the entire set of data points
double *x;
double *y;
int numValues;
// save zoomed values
double xval_start; // x[first] value in zoom window
double xval_end; // x[last] value in zoom window
int xyindex_start; // first x[index_start] in zoom window
int xyindex_end; // last x[index_end] in zoom window
double Ymin, Ymax; // within zoom window

}MSSpectrum;


// prototypes
int MSObjectReadXY(char *path, MSObject *object);

These are global, and any .c files that include this .h file and use the
MSObject contain also only global functions.

I reallllly want just to add a constructor and destructor to MSObject,
and not have to change the signature of every function that uses this
object.

I have tried every combination of classes, structs, typedefs and
otherwise but nothing will compile that will allow me to add a
constructor to this thing.

What do I need to do?

What you need to do is just what I suggested in response to your
previous post on this subject: post a *minimal* but *complete* sample
that demonstrates the error you are getting. You can probably do just
what you want to do, assuming there's no initialization of these
structs like this:

MSObject obj = { 0, 0 /*...*/ };

Cheers! --M
 
E

Eric.Malenfant

Bryan a écrit :
Okay, in some legacy code, in the .h file I have exactly this:
typedef struct MSObject
{
// this refers to the entire set of data points
double *x;
double *y;
int numValues;
// save zoomed values
double xval_start; // x[first] value in zoom window
double xval_end; // x[last] value in zoom window
int xyindex_start; // first x[index_start] in zoom window
int xyindex_end; // last x[index_end] in zoom window
double Ymin, Ymax; // within zoom window

}MSSpectrum;


// prototypes
int MSObjectReadXY(char *path, MSObject *object);

These are global, and any .c files that include this .h file and use the
MSObject contain also only global functions.

I reallllly want just to add a constructor and destructor to MSObject,
and not have to change the signature of every function that uses this
object.

I have tried every combination of classes, structs, typedefs and
otherwise but nothing will compile that will allow me to add a
constructor to this thing.

You mention ".c files". Would these happen to contain (as the name
suggests) C (and not C++) code?
 
H

Howard

Bryan said:
Okay, in some legacy code, in the .h file I have exactly this:
typedef struct MSObject
{
// this refers to the entire set of data points
double *x;
double *y;
int numValues;
// save zoomed values
double xval_start; // x[first] value in zoom window
double xval_end; // x[last] value in zoom window
int xyindex_start; // first x[index_start] in zoom window
int xyindex_end; // last x[index_end] in zoom window
double Ymin, Ymax; // within zoom window
}MSSpectrum;

This is different from what you showed before. (Perhaps something is
looking for "MSSpectrum"?)
// prototypes
int MSObjectReadXY(char *path, MSObject *object);

These are global, and any .c files that include this .h file and use the
MSObject contain also only global functions.
("These"? I only see one function prototype.)

Perhaps you're compiling with a C compiler instead of a C++ compiler? I've
seen at least one compiler that assumes a .c file should be compiled as C
(whereas it would compile a .cpp file as C++ code).
I reallllly want just to add a constructor and destructor to MSObject, and
not have to change the signature of every function that uses this object.

So go ahead. And you don't need to change it to a class to do so. A struct
can have a constructor and destructor, too. (Unless you're using some
REALLY old compiler!)
I have tried every combination of classes, structs, typedefs and otherwise
but nothing will compile that will allow me to add a constructor to this
thing.

What do I need to do?

Post the code that your compiler reports an error on, and post the error
message text as well. And if you can post a complete, small example that
will cause the same error when WE compile it, we could help better. (We
can't just guess what the error is, or what the code is that generates the
error.)

-Howard
 
R

Richard Herring

Bryan said:
Okay, in some legacy code, in the .h file I have exactly this:
typedef struct MSObject
{
// this refers to the entire set of data points
double *x;
double *y;
int numValues;
// save zoomed values
double xval_start; // x[first] value in zoom window
double xval_end; // x[last] value in zoom window
int xyindex_start; // first x[index_start] in zoom window
int xyindex_end; // last x[index_end] in zoom window
double Ymin, Ymax; // within zoom window

}MSSpectrum;


// prototypes
int MSObjectReadXY(char *path, MSObject *object);
^^^^^^^^
Are you sure that's _exactly_ what's in the file?

MSObject is the struct tag, but the name of the type is MSSpectrum.
 

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

Similar Threads


Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,235
Latest member
Top Crypto Podcasts_

Latest Threads

Top