Using gcnew : gcnew « Language Basics « Visual C++ .NET

Home
Visual C++ .NET
1.2D
2.Class
3.Collections
4.Data Type
5.Database ADO.net
6.Delegate
7.Development
8.File Directory
9.Function
10.Generics
11.GUI Form
12.Language Basics
13.Network
14.Reflection
15.Security
16.Statement
17.Structure
18.Thread
19.XML
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Visual C++ .NET » Language Basics » gcnew 
Using gcnew
 
#include "stdafx.h"
using namespace System;

ref class ParentClass{
public:
    ParentClass() : PVal(10) {}
    ParentClass(int inVal: PVal(inVal) {}
    ParentClass(const ParentClass %p: PVal(p.PVal) {}

    int PVal;
};

ref class ChildClass : public ParentClass{
public:
    ChildClass () : CVal(20) {};    
    ChildClass (int inVal1, int inVal2: ParentClass(inVal1), CVal(inVal2) {}
    ChildClass(const ChildClass %vals: ParentClass(vals.PVal), CVal(vals.CVal) {}
    int CVal;
};

void main()
{
    ChildClass ^c1 = gcnew ChildClass(5,6)// Constructor
    ChildClass  c2 = *c1;                   // Copy Constructor

    c1->CVal = 12;        // Change original, new unchanged

    Console::WriteLine("c1=[{0}/{1}] c2=[{2}/{3}]"
        c1->PVal, c1->CVal, c2.PVal, c2.CVal);


   
  
Related examples in the same category
1.Create a handle to an int
2.Assign new value to dereferenced int
3.generic gcnew
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.