By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,376 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

constructor and configuration file

P: n/a
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),pathToVLDoneFil e(pathToVLDoneStr),
pathToInputFile(inputStr),pathToDmapFile(dmapStr),

pathToAnalysisFile(analysisStr),pathToVLUnixFile(u nixStr){}; // 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,

Mar 8 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
utab wrote:
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.
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),pathToVLDoneFil e(pathToVLDoneStr),
pathToInputFile(inputStr),pathToDmapFile(dmapStr),

pathToAnalysisFile(analysisStr),pathToVLUnixFile(u nixStr){}; // 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
Mar 8 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.