Hi All
I am relatively new to the C++ world . Facing some problem , while initializing an array of objects .
Suppose i have a class Rectangle . I want to have a pointer to an array of objects to the class . How do i invoke the Class Constructor , for a paricular object in the arraylist.
class Rectangle
{
public :
int side1 , side2;
Rectangle(int,int);
Rectangle();
void get_area();
private :
protected :
};
Rectangle::Rectangle(int x, int y)
{
side1=x;
side2=y;
}
void Rectangle::get_area()
{
cout<<"Area :"<< side1*side2<<endl;
}
Rectangle *ptr_arr;
ptr_arr=new Rectangle[2] ; // pointer to an array of objects to the class
// Now how do i initialize the dimensions for the ptr_arr[1] object , using the constructors ???
<< moderator edit: added [code][/code] tags >>
Pplz Help
Best Regards
Varun