Re: structures and classes
If the structure is tightly related to the class, it can be declared as in your code however it might be better to declare it inside the class.
Code:
class readHeader : ... {
public:
struct headerInfo {
int numberOfSamples;
int numberOfLines;
// ...
};
headerInfo getHeaderInfo() const { ... }
};
Note that the fully qualified name of the struct then becomes readHeader::headerInfo.
Re: structures and classes
I don't think i'm the one who can give an advice about "best practices"...
Anyway , what do you mean "I can of course access the structure directly" ? Maybe i'm missing something but it seems like you're confusing type's declaration with a type's instance. You've got a structure's declaration placed in a header file : that's it , this way you can do this :
Code:
// in wherver header/source file the readheader.h is included //
headerInfo newHeaderInfoObject ;
newHeaderInfoObject.numberOfSamples = 10 ;
// ...
// etc.
However , If you had the headerInfo declaration placed within a readHeader class :
Code:
// in wherver header/source file the readheader.h is included //
readHeader::headerInfo newHeaderInfoObject ; // if headerInfo declaration is placed in a PRIVATE section : ERROR
readHeader::headerInfo newHeaderInfoObject ; // if headerInfo declaration is placed in a PROTECTED section : ERROR
readHeader::headerInfo newHeaderInfoObject ; // if headerInfo declaration is placed in a PUBLIC section : OK
But , getting back to "I can of course access the structure directly" : since you've placed "headerInfo p_hdrinfo" in the PRIVATE section , there is no way you can access it directly .Isn't it the reason you've created methods for accessing it ?^^ So , depending on how you're gonna use the readHeader class in your application's data architecture , you'll probably have to place it in either PRIVATE or PROTECTED sections...