Array of objects

// Arrayofobj.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

class Test
{
int i;
int j;
public:
Test(int a , int b )
{
i=a;
j=b;
}
void getval()
{
std::cout << i <<"\t" << j ;
}

};

int _tmain(int argc, _TCHAR* argv[])
{
Test obj[3] = { Test(10,20) , Test(30,40) ,Test(50,60) };

Test *ptr;

ptr = obj;
for(int i = 0; i<3; i++)
{
ptr->getval();
ptr++;
}
return 0;
}

Comments

Popular posts from this blog

Smart Pointers in C++ and How to Use Them

Operator Overloading in C++

How would you read in a string of unknown length without risking buffer overflow