Author Topic: C++/CLI Recursive Function  (Read 2645 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8767
  • AKA Daniel
C++/CLI Recursive Function
« on: December 09, 2008, 11:24:33 AM »
Anyone see any problems with doing this? Note outList is passed by reference

Code: [Select]
static void PairToList(Object^ o, TypedValueList ^%outList )
  {
    if(o->GetType() == LSharp::Pair::typeid)
    {
      LSharp::Pair ^p = (LSharp::Pair^)o;
      outList->Add(TypedValue((short)LispDataType::ListBegin));
      for each(Object^ ob in p)
      {
        PairToList(ob , outList);
      }
      outList->Add(TypedValue((short)LispDataType::ListEnd));
    }
    else
    {
      outList->Add(MCmds::ObjectToTypedValue(o));
    }
  }

TonyT

  • Guest
Re: C++/CLI Recursive Function
« Reply #1 on: December 10, 2008, 02:53:50 AM »
Anyone see any problems with doing this? Note outList is passed by reference

Code: [Select]
static void PairToList(Object^ o, TypedValueList ^%outList )
  {
    if(o->GetType() == LSharp::Pair::typeid)
    {
      LSharp::Pair ^p = (LSharp::Pair^)o;
      outList->Add(TypedValue((short)LispDataType::ListBegin));
      for each(Object^ ob in p)
      {
        PairToList(ob , outList);
      }
      outList->Add(TypedValue((short)LispDataType::ListEnd));
    }
    else
    {
      outList->Add(MCmds::ObjectToTypedValue(o));
    }
  }

From just looking at it, I don't see anything that sticks out, aside
from the fact that if TypedValueList is a reference type (e.g. a
class), there shouldn't be any need to pass it by-reference, since
it already is a reference to an instance, rather than a copy of it.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8767
  • AKA Daniel
Re: C++/CLI Recursive Function
« Reply #2 on: December 11, 2008, 08:38:14 AM »

... TypedValueList is a reference type (e.g. a
class), there shouldn't be any need to pass it by-reference, since
it already is a reference to an instance, rather than a copy of it.


Doh! You are right! Thanks Tony   :-)