View Single Post
Copernicus's Avatar
Posts: 1,986 | Thanked: 7,698 times | Joined on Dec 2010 @ Dayton, Ohio
#7
Originally Posted by Halftux View Post
It is also possible to use enum instead of switch.

Maybe this is interesting.
http://schneide.wordpress.com/2010/1...itch-use-enum/
While this is a cute way to use an enum, I don't think it'd be something I'd do. IMHO, the best value of an enum is to make clear which of a variety of states your code is in. (This is Pichlo's quite valid criticism of my if/then suggestion, as I skipped the use of one of his two enum values.) If you hide the code inside the enum declaration itself, you're basically moving from declaring a set of states to declaring a set of function pointers, which is a very different beast.

Besides, we've got C++ here. I think it'd be better to go all the way and create a set of sibling classes. Something like this:

Code:
class indexType
{
public:
  virtual void addItems() = 0;
};

class frequency: public indexType
{
public:
  void addItems(); // Add the Hz items
};

class period: public indexType
{
public:
  void addItems();  // Add the Seconds items
};
 

The Following 2 Users Say Thank You to Copernicus For This Useful Post: