Initialize a Structure : Definition « Structure « Visual C++ .NET






Initialize a Structure

 
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
struct Book {
    char *Title;
    char *Artist;
    int YearReleased;
    Book(char *t, char *a, int y) {
        Title = t; Artist = a; YearReleased = y;
    }
};

int main(void)
{
    Book b1("A","B",2001);
    Book *b2 = new Book("A","B",1974);
    Console::WriteLine(b1.Artist);
    Console::WriteLine(b2->Artist);
    return 0;
}

   
  








Related examples in the same category

1.Declare a Structure Type
2.Create a Structure
3.Access a Structure
4.Complex struct
5.struct implements IComparable