Question: In C# its possibly to use [AsDynamic](http://blogs.msdn.com/b/davidebb/archive/2010/01/18/use-c-4-0-dynamic-to-drastically-simplify-your-private-reflection-code.aspx) to invoke a overloaded method on a subclass (example [here](https://github.com/gregoryyoung/m-r/blob/master/SimpleCQRS/Domain.cs)) thus allowing an abstract class to invoke methods it does not itself define. Is something similar possible with Scala 2.9 **applyDynamic** ?. I tried the following

```
abstract class AggregateRoot extends Dynamic {
  def applyChange(event: Event) {
    this.applyDynamic("handleEvent")(event) 
  }
  // this does not work
  def applyDynamic(name : String)(args: Any*) = this
}

```

used like this 

```
class InventoryItem extends AggregateRoot {
  def handleEvent(event: InventoryItemCreated) {
    println("received InventoryItemCreated")
  }

  def handleEvent(event: InventoryItemDeactivated) {
    println("received InventoryItemDeactivated")
  }
}

```

where **InventoryItemCreated** and **InventoryItemDeactivated** both are events

```
class Event;

class InventoryItemDeactivated extends Event; 

class InventoryItemCreated extends Event; 

```

I then expect to be able to do something like this

```
  var aggregate : AggregateRoot = new InventoryItem
  var event = new InventoryItemDeactivated
  aggregate.applyChange(event) // should print "received InventoryItemDeactivated"

```

but I cannot figure out how to define **applyDynamic** (in **AggregateRoot**) so that it can invoke overloaded methods in subclasses at runtime without itself defining them. Other solutions that achieve the same result are welcome (perhaps structural typing can come in handy ?).

Answer: 
In C++, `std::list` does not support random access lookup via `operator []`. If you are going to continue to use a list, you should look at the `std::advance` function.

```
list<string>::iterator itr = whichList.begin();
std::advance(itr, i);
if (itr->empty())
{
 /* ... assuming that you're testing for an empty string */
}

```

If possible, you might want to consider other standard containers, such as `std::vector` or `std::deque`, both of which provide random access lookup via `operator []`.
I think you should use a vector for this problem.