constructor and configuration file

U

utab

Dear all,

I have a class that takes some paths as parameters and does some
operations on the files under these paths. I used Boost filesystem
library for that.

My question is on the construction: Now I am using a list of path
parameters when I create an object of this class but I was thinking to
call a configuration file reader function inside my constructor which
takes care of the initialization of the paths through this function.
From an introductory OOP course, I remember that constructors should
only be used for the initialization of the data members of the class.
Not for calling other functions and operations. If you want to do sth
like this encapsulate this in a function which is also a member of the
class.

This is what I use as the constructor in the header file:

SA(const std::string& pathToVLInStr,const std::string&
pathToVLStartStr,
const std::string& pathToVLOutStr,const std::string&
pathToVLDoneStr,
const std::string& inputStr,const std::string& dmapStr,
const std::string& analysisStr, const std::string&
unixStr):

pathToVLInputFile(pathToVLInStr),pathToVLStartFile(pathToVLStartStr),

pathToVLOutputFile(pathToVLOutStr),pathToVLDoneFile(pathToVLDoneStr),
pathToInputFile(inputStr),pathToDmapFile(dmapStr),

pathToAnalysisFile(analysisStr),pathToVLUnixFile(unixStr){}; // ctor

I need some advice on this. Becasuse in the main file I do not want
to type everything. But is that a good idea to do that from inside the
constructor or in another independent class function?

Best regards,
 
J

John Harrison

utab said:
Dear all,

I have a class that takes some paths as parameters and does some
operations on the files under these paths. I used Boost filesystem
library for that.

My question is on the construction: Now I am using a list of path
parameters when I create an object of this class but I was thinking to
call a configuration file reader function inside my constructor which
takes care of the initialization of the paths through this function.
only be used for the initialization of the data members of the class.
Not for calling other functions and operations. If you want to do sth
like this encapsulate this in a function which is also a member of the
class.

I've never heard that advice before, I don't agree with it.
This is what I use as the constructor in the header file:

SA(const std::string& pathToVLInStr,const std::string&
pathToVLStartStr,
const std::string& pathToVLOutStr,const std::string&
pathToVLDoneStr,
const std::string& inputStr,const std::string& dmapStr,
const std::string& analysisStr, const std::string&
unixStr):

pathToVLInputFile(pathToVLInStr),pathToVLStartFile(pathToVLStartStr),

pathToVLOutputFile(pathToVLOutStr),pathToVLDoneFile(pathToVLDoneStr),
pathToInputFile(inputStr),pathToDmapFile(dmapStr),

pathToAnalysisFile(analysisStr),pathToVLUnixFile(unixStr){}; // ctor

I need some advice on this. Becasuse in the main file I do not want
to type everything. But is that a good idea to do that from inside the
constructor or in another independent class function?

Best regards,

I don't see the point of having a seperate function just for the sake of
it. From what you've described so far I would just do everything in the
constructor.

john


john
 

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

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top