FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
September 01, 2005

C++/CLI: Cloning

(Page 11 of 11)

September, 2005: C++/CLI: Cloning

Listing 9

public ref class Test : ICloneable
{
     int data;
     static int objectCount = 0;
public:
     Test()
     {
          data = 0;
          ++objectCount;
     }
     Test(int value)
     {
          data = value;
          ++objectCount;
     }
     virtual String^ ToString() override
     {
          return String::Concat(data, ", ", objectCount);
     }
     virtual Object^ Clone()
     {
/*1*/          Test^ copy = static_cast<Test^>(MemberwiseClone());
/*2*/          ++objectCount;
          return copy;
     }
};
int main()
{
/*3*/     Test^ t1 = gcnew Test;
     Console::WriteLine("t1 using new:   {0}", t1);
/*4*/     Test^ t2 = static_cast<Test^>(t1->Clone());
     Console::WriteLine("t2 using Clone: {0}", t2);
/*5*/     Test^ t3 = gcnew Test(1);
     Console::WriteLine("t3 using new:   {0}", t3);
/*6*/     Test^ t4 = static_cast<Test^>(t3->Clone());
     Console::WriteLine("t4 using Clone: {0}", t4);
}
}

Previous Page | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK