Function assert on windows VC7.1

2008-09-16
2013-04-08
  • Chen Zuopeng
    Chen Zuopeng
    2008-09-16

    Function assert on windows when you try to copy a Functor.

    here is the example code:
    class LokiTest
    {
    public:
        void operator () ()
        {
            cout << "run here" << endl;
        }
    };

    int main (int argc, char** argv)
    {
        LokiTest lt0;
        Function <void (void)> function0 (lt0);
        function0 ();
        Function <void (void)> function1 (function0);
        function1 ();
        return 0;
    }

     
    • Chen Zuopeng
      Chen Zuopeng
      2008-09-17

      additional:
          it work well with gcc.  i havn't find out why the assert show up on windows.  i just comment it. who can help me?

      Allen

       
      • Peter Kuemmel
        Peter Kuemmel
        2008-09-17

        There are no problems with VC8 and VC9, therefore i assume it is a VC7.1 bug, and we can't do much.

         
    • Chen Zuopeng
      Chen Zuopeng
      2008-09-18

      OK, just assume it is a VC7.0 bug.  but i have another problem.
      let's try do this:
      class LokiTest
      {
      public:
          LokiTest () : i (0) {}
          void operator () ()
          {  
              i++;
              cout << "run here" << endl;
          }  
          int i;
      };

      int main (int argc, char** argv)
      {
          LokiTest lt;
          Function <void (void)> func (lt);
          func ();
          cout << lt.i << endl;
      }

      result:
      run here
      0

      is this right??
      Why does the Functor copy the LokiTest instance. this behave is out of my thought.

      dose the Functor should keep a reference of a instance?