Re: What to do after the creation of an object with a factory?
In article <1164507567.812276.310530@l39g2000cwd.googlegroups.com>,
Craig Scott <audiofanatic@gmail.com> wrote:
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.
std::lower_bound and test result, not std::binary_search, unless
you only want to query existance. Further it is likey that an array of
string is going to be at least as fast as a vector with a fixed at
runtime size, It is as good as any other C++ way, and probably the
fastest
as there is less room to miss an optimization.
class SpecialShape:public Shape
{
std::string data['n'-'a'+1];
public:
std:;string & getData(ch x) {return data[x-'a'];}
// ...
};
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]