none
Does CLI needs Update???? RRS feed

  • Question

  • Hi everybody.

    I've found a very strange problem.
    This code doesn't work,( it hangs up the program):

    MyClass^ MyClass::LastChild::get()

       MyClass^appo,^tmp=this;
      while(tmp->Child.Count)
     {
         tmp=tmp->Child[0];
      };
      return tmp;
    }

    This One, instead, works fine:

    MyClass^ MyClass::LastChild::get()

       MyClass^appo,^tmp=this;
      while(tmp->Child.Count)
     {
         appo=tmp;tmp=tmp->Child[0];
         if(appo==tmp)
         {
              DoSomething(appo);
              break;
         }
      };
      return tmp;
    }

    The strange is that it DoSomething isn't call.
    It seams that a few time is needed to update the pointers.

    Is it possible??
    Am I doing something wrong.

    Thanks a Lot,
    Peppe.

    • Edited by peppebck Saturday, July 5, 2008 11:50 PM Missed piece
    Saturday, July 5, 2008 11:48 PM

All replies

  • How come it is Child.Count and not Child->Count?  Child is a value type??
    Hans Passant.
    Sunday, July 6, 2008 5:20 PM
    Moderator
  • Nobugz,


    public ref class MyClass
    {
       System::Collection::Generic::List<MyClass^> Child;
    };

    thanks.
    Sunday, July 6, 2008 5:52 PM
  • I'm surprised that compiles, it probably has something to do with your problem.   List<> is a reference type, you need the "hat":

      List<MyClass^>^ Child;

    Hans Passant.
    Sunday, July 6, 2008 6:26 PM
    Moderator
  • Nobugz, it compiles and, except this case, works fine.

    I could try your suggestion but, do you think it could solve my problem??? If it compiles...!?!?!?!
    Sunday, July 6, 2008 6:33 PM
  • Not sure what you are asking me.  From where I sit, it looks like a pretty major compiler bug to allow a reference type to be a value member of a class.  It is a construct that is not possible to express in a language like C# or VB.NET.  It was added to the language since C++ programmer's have a real hang-up about deterministic destruction.  Inside a function, not a class.  Since C++/CLI is the new kid on the block, I'd have to assume that this (possible) bug was just not ever detected until you programmed it.  And not put to the test because the gurus would never forget the hat.

    If you are committed to not use the hat, you could post to the Connect web site to share your experiences with what goes wrong when you don't and why or why not that would be a compiler bug.  Or you could use the hat and see if that fixes your problem.  Please let us know how it turned out.

    Hans Passant.
    Sunday, July 6, 2008 10:58 PM
    Moderator
  • nobugz, I'll use the hat and I'll let you know as soon as possible.

    Thanks a lot, Peppe.
    Monday, July 7, 2008 10:25 AM
  • nobugz...it doesn't work.


    it seams like the assignment  (tmp=tmp->Child[0]) is non modal, in the next loop the old tmp is used so that the loop never ends.

    if I put some operations in the loop to loose time it works.

    I'll try something simplier to reproduce and verify the problem.
    Monday, July 7, 2008 3:21 PM