Pointer to classes

Jan 29, 2014 at 3:52am
So i was reading the Cplusplus tutorials for some recap on Polymorphism and I saw:

1
2
   Polygon poly;
   Polygon* ppoly3 = &poly;


So im left wondering if maybe it would be the same thing as

 
   Polygon* ppoly3 = new Polygon();


Im just stuck on polymorphism a bit so even if im completely wrong, what would be the difference?

Jan 29, 2014 at 3:55am
First off, that has nothing to do with polymorphism.

The two examples are not the same; the first creates a pointer to an object created on the stack, and the second allocates memory for an object that is created on the heap.
Jan 29, 2014 at 4:16am
Well actually it does have something to do with polymorphism because that concept can't be implemented without pointers.
Jan 29, 2014 at 4:26am
Cody0023 wrote:
Well actually it does have something to do with polymorphism because that concept can't be implemented without pointers.
Not only is that statement completely wrong, it's like saying that essays are related to fingers because essays can't be written without fingers.
Jan 29, 2014 at 4:29am
I think he means that you cant do polymorphism without that concept? eitherways, that concept i learned in the polymorphism tutorial, thats why i came across it...i know thats not what polymorphism is...
Last edited on Jan 29, 2014 at 4:30am
Jan 29, 2014 at 4:32am
I didn't mean to sound rude - I was just trying to emphasize you can perform polymorphism just fine without pointers. I'm not very good at not sounding rude though.
Jan 29, 2014 at 4:40am
No not really rude just random XD eitherways the question is solved (more or less) so ill just mark as solved :P
Jan 29, 2014 at 5:48am
without pointers or references i meant.
Jan 29, 2014 at 2:14pm
That still makes no sense whatsoever.
Topic archived. No new replies allowed.