Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Serious question about sepples

Name: Anonymous 2008-11-27 6:01

I am aware that there are a lot of better languages, thank you.

Imagine this: I want to make class -- a mapping, just like an array, but indexes are strings, not numbers.
I make a mapping class with virtual set and get functions, and then create two classes - hashtable and bintree, inheriting them from mapping. I also want to iterate through all elements of hashtable (but not bintree - just because I don't need it and don't want to write the code). I create another class iter with two virtual functions - first and next (or whatever), and inherit hashtable from both mapping and iter.

Now, I can have a function that accepts mapping - and I can send it my hashtables and bintrees. I want to write a function that accepts an object that is both mapping and iter (it's hashtable, but I want it to accept all objects inherited from mapping and iter, not just this particular hashtable class). What type should I use?

The only answer I can come up with is to use another class - iter_mapping inherited from there two, but this looks plain stupid. What if I have more than two of these classes? 8, for example? Do I have to create a new dummy class for each combination?

Name: Anonymous 2008-11-28 2:18

>>1
It sounds like that "concepts" from C++0x could solve this--but you'd have to wait a few years to use them.

Short answer: anything that is a "mapping" should be iterable, so suck it up and write the code to iterate through a binary tree. Or, at least, make the bintable implement iteration in a way that doesn't actually iterate, so that nothing happens.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List