Re: What to do after the creation of an object with a factory?
Well, it doesn't look very manageable to have 15 similar attributes
in a class.
In case that they are not frequently used, you can write instead:
// in the class definition
std::map<std::string,std::string> data;
...
obj.data[p->first] = p->second;
Since the number and name of each variable doesn't change, you could
also use the faster approach of storing the data in a sorted vector and
using std::binary_search to access them. This would be a bit faster
than std::map, although maybe it would not be a huge difference for an
array this small.
Another approach, but one I would hesitate to recommend unless
performance is really important to you is to take advantage of the fact
that char can be implicitly converted to int and used as an array
index. Since all your variables are named with characters consecutively
from a to n (which I'm guessing you only did for illustration purposes
instead of using the actual names from your particular case), they can
be used as array indices thus:
class SpacialShape : public class Shape
{
.......
private:
std::vector<string> data_;
//string a,b,c,d,e,f,g,h,i,j,k,l,m,n;
};
You would then access the data something like this:
string& SpacialShape::getData(char ch)
{
assert(ch >= 'a');
assert(ch <= 'n');
return data_[ch];
}
I can't say I would particularly recommend this strategy (it is really
not the C++ way of doing things), but if you want a hack that works,
maybe this is useful.
--
Computational Fluid Dynamics, CSIRO (CMIS)
Melbourne, Australia
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]