I am new to C++ classes and facing a simple problem but unfortunately didn't get the solution yet so that's why posting it here. I made a struct like this
struct mono_scan_temp
{
double num_filters[1][1];
double filter_data[1024][153][3];
double shutter_speed[1][3];
double resolution[1][153];
double monochromator_gain[1][1];
double zero[1][1];
double saturation[1][1];
double dark_noise[3][1024];
double slit_size[1][1];
double version[1][1];
};
This struct is in .h file then i instantiated it in the same header file like this
mono_scan_temp scan_data_temp;
Now when i am trying to access its members from a main file it is giving this error.
Error 43 error C2228: left of '.num_filters' must have class/struct/union
The members of this struct will hold a data from .mat file like this
Mat_VarReadData(mat,field_num_filters,scan_data_temp.num_filters,start_num_filters,stride_num_filters,edge_num_filters);
for(i=0;i<field_num_filters->dims[0];i++)
for(j=0;j<field_num_filters->dims[1];j++)
printf("%f \n ",scan_data_temp.num_filters[i][j]);
and also the header file is included in the main file.
I know it a simple problem but sorry in advance for my limited knowledge.
Looking forward for a favorable response.
Thanks
You apparently have a subexpression XXX.num_filters
, and XXX
isn't an object of type mono_scan_temp
.
Defining zero
to be a two-dimensional array of bound 1 in each dimension, and a member of a struct
, is what those in the industry sometimes call a "code smell."
This line does not go in the header file; it should go in the .cpp
file. To declare a global object as part of an interface in the header, add extern
before the declaration: extern mono_scan_temp scan_data_temp;
. This is in addition to defining in the .cpp
file.
And although the rest of your program appears to be in C, this line does require C++, so be sure you are using a C++ compiler and the file name ends in .cpp
(if that's really what you want).
mono_scan_temp scan_data_temp;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.