Topic: object initialization


Author: twoodard@nike.heidelberg.edu (Tim Woodard)
Date: 1997/04/24
Raw View
Is it bad practice to use a class/struct for the sole purpose of
initializing other classes?

Example:

struct ObjectInitializer {
    // some data used to initialize a class
};

class Object {
public:
    Object(const ObjectInitializer& init) {
        // parse out the needed data from the ObjectInitializer
        // for memory allocation, etc...
    }
    ...
};

The reason I want to do something like this is that I have a class
hierarchy where all of the classes store the same type of data, but
the data is stored differently from class to class.  The
ObjectInitializer tells the Object how much memory to allocate, etc...
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]