// JP opened flex table

Click to See Complete Forum and Search --> : C++:Initializing an array of object with constructor


Zulfi Khan2
March 25th, 2002, 03:00 AM
I have a class containing two data members & I have created & array of object but I am not able to initialize this array with constructor.
Can some body plz help me?
#include "iostream.h"
class test{
int a;
int b;
public:
test(int ar1,int ar2){
a=ar1;
b=ar2;
}
void show(){
cout<<"a="<<a;
cout<<"b="<<b;
}
};

main() {
test obj[2]={{2,3},{2,3}};
obj[0].show();
obj[1].show();

}

SatishKini
March 28th, 2002, 01:56 AM
try using
test obj[2]={test(2,3),test(2,3)};


Hope this helps
Regards
Kini

//JP added flex table