Hi! I'm new to C++, but I have programmed a bit in Java before. I was wondering about polymorphism in C++. I know you can initialize a superclass with a subclass by typing:
But say we have a class called ShapeCollection, which has two Shape objects. What if we wanted to initialize these objects to Rectangles or Circles depending on what argument you passed to the constructor?
Rectangle() creates a temporary object that will be destroyed at the end of the line so you wouldn't want to store a pointer to it. You probably want to create the objects with new instead.