Menu

inherit simulation in c++/IEnumerator problem

Help
Virnas
2007-06-21
2013-04-23
  • Virnas

    Virnas - 2007-06-21

    I first wanted to thank you for creating this library, it has been extraordinarily helpful.

    I'm trying the create a simulator that inherits from the simulation class.  However, this new simulator is in c++.  Everything almost works.  The problem is that there is no equivalent statement for yield break.  I created an iterator, but it does not work as intended.  My processes will each run once, while they should run endlessly.  Has anyone implemented a subclass of simulation in c++ before?  How should I deal with the enumerators?

    Thanks for your help.

     
    • Eric Roe

      Eric Roe - 2007-06-24

      I presume the problem is not the subclassing, but rather creating the ProcessSteps delegate or overiding Process.GetProcessSteps().  Unfortunately, as far as I can see, C# is the only Visual Studio language that supports a "yield return/break" statement.

      There's a bunch of extra plumbing behind the scenes that the C# compiler actually sets up when you use the "yield" statement.  Open the BarberShop.exe program in the MSIL decompiler and look at the Barber, Customer, or Shop classes and you'll see a generated inner-class named d__0.  This is something the compiler creates to support maintaining the state of the iterator method.  In C++, since there's no "yield" statement, you'd need to write an IEnumerator<Task> implementation yourself, which would be returned by your ProcessSteps delegate (or from the Process.GetProcessSteps method).  Certainly more work than in C#, but it should be possible.

         — Eric —

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.