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;
}
//
#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
Post a Comment