Hi Experts can I do dynamic binding like this.
objshapes is the parent class called Shape and Rectangle is the child class. I have a few child classes so depending which shape the user selects, I need to bind the correct shape to the objShapes. So i thought i can bind like this. but i getting an error.
Shape *objShapes[3];
objshapes[size]= &new Rectangle(3,lvaule,5)
//error: lvalue required as unary ‘&’ operand
Hope someone can assist. Thanks
IS THIS CORRECT
objshapes[size]= new Rectangle(3,lvaule,5)
This declares objshapes as an array of 3 pointers-to-Shape.
This is non-sensical.
Yes1, that is correct.
newreturns a pointer-to-Rectangle, which can be stored in a variable of type pointer-to-Shape. Sinceobjshapesis an array of pointers-to-Shape.objshapes[size]is pointer-to-Shape — which can accept a pointer-to-Rectangle.1. Assuming that
sizeis convertable to an integral type, and has the value0,1, or2.