Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > constructor and configuration file

Reply
Thread Tools

constructor and configuration file

 
 
utab
Guest
Posts: n/a
 
      03-08-2007
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,

 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      03-08-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A constructor calling another constructor (default constructor)? Generic Usenet Account C++ 10 11-28-2007 04:12 AM
Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicK Mike ASP .Net 5 08-15-2007 08:57 AM
Confused by the constructor and cop-constructor. Xiangliang Meng C++ 9 06-25-2004 03:44 PM
calling a constructor within a constructor Brett Irving C++ 3 06-29-2003 10:43 AM
why it's not possible calling constructor from constructor? Giulio C++ 9 06-25-2003 03:56 PM



Advertisments