I find myself having a hard time deciding when and how to use member functions within a class.
Situation A:
i have a private member 'int x', and a method setX(int n){ x = n; }.
within a private member 'do_something(void)' i need to change the value of x...do i use setX() or simply x = a_number; ?
Situation B: (this will make more since after looking at the code)
i have a class which evaluates regular expressions.
i have a private member 'vector<int> regex' and a constructor
'myclass(const string &)'. a private method 'convert(const string &)' which converts a string into a vector of integers. there is another private member called 'makeValid(???)' which ensures a regular expression is valid by adding various characters to it. (ex: closing a group with ')' ) ...and then another private method which is called 'prepare(const string &)'
should i pass regex into these functions and then return regex?
like so
or just let the methods take care of itCode:myclass::myclass(void){ prepare(); } void myclass::prepare(const string &source) { regex = convert(source); regex = makeValid(regex); //theres quite a few more function that will manipulate //regex the same way makeValid does }
i know this seems like a trivial question, but all my classes eventually turn into spaghetti no matter how i implement themCode:myclass::myclass(void){ prepare(); } void myclass::prepare(const string &source) { convert(source); //accesses regex directly makeValid(void); //ditto //theres quite a few more function that will manipulate //regex the same way makeValid does }



LinkBack URL
About LinkBacks



CornedBee
). The worst problem with them is that RAII is not implementable, which means that I always need a finally - isn't it weird how these languages (Java, C#) promote finally as an advantage when it's really a hack to overcome the lack of scoped destructors? 