constructor and configuration file

Discussion in 'C++' started by utab, Mar 8, 2007.

  1. utab

    utab Guest

    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,
     
    utab, Mar 8, 2007
    #1
    1. Advertising

  2. 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),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
     
    John Harrison, Mar 8, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    0
    Views:
    832
  2. Giulio
    Replies:
    9
    Views:
    1,047
    Patrick Kowalzick
    Jun 25, 2003
  3. Xiangliang Meng
    Replies:
    9
    Views:
    436
    Chris Theis
    Jun 25, 2004
  4. Giox
    Replies:
    1
    Views:
    393
  5. Generic Usenet Account
    Replies:
    10
    Views:
    2,248
Loading...

Share This Page