I was wanting to know if it is considered bad practice to declare a structure in my class? a snippet of the class definition below,
#ifndef READHEADER_H
#define READHEADER_H
#include <QObject>
...
struct headerInfo{
int numberOfSamples;
int numberOfLines;
int numberOfBands;
int dataType;
QVector<double> wavelengths;
};
{
Q_OBJECT
public:
explicit readHeader
(QObject *parent
= 0);
headerInfo getHeaderInfo();
...
private:
...
signals:
...
public slots:
private:
...
headerInfo p_hdrinfo;
};
#endif // READHEADER_H
#ifndef READHEADER_H
#define READHEADER_H
#include <QObject>
...
struct headerInfo{
int numberOfSamples;
int numberOfLines;
int numberOfBands;
int dataType;
QString fileName;
QVector<double> wavelengths;
};
class readHeader : public QObject
{
Q_OBJECT
public:
explicit readHeader(QObject *parent = 0);
headerInfo getHeaderInfo();
...
private:
...
signals:
...
public slots:
private:
...
headerInfo p_hdrinfo;
};
#endif // READHEADER_H
To copy to clipboard, switch view to plain text mode
So in my main program when include my readheader.h I can of course access the structure directly, but instead I use the getheaderinfo function which returns the structure(i don't really know what my reasoning behind that was). This code/class will never be distributed to anyone and any code that does use it will be writing. I am aware that the way I have done it also allows the structure contents to be changed anywhere in my code. Doesn't feel right.
I should also say that the header file contains various information in various formats e.g. int, double, string and some vectors.
I cant help but feel that this is not the right thing to do and is most likely considered really bad practice. I am still very new to C++ and Qt. I did initially have a ton of getter public functions in my class but wanted to return everything at once rather than making umpteen million calls.
Any help/advice on such things would be really appreciated.
Cheers
Oz
Bookmarks