Okay, so I'm done nerd-raging now. Sorry, Arch totally scared the poop out of me because my stupid Gnome shell took forever to load so I was in no mood to tolerate such useless posts, ooga. You shouldn't even be here if you're going to post like that, tbh.
Okay, so I wrote this code that seems to show what I was talking about, that allocating a new real shape (struct square, circle, triangle) and how the inheritance gives it its own parent class. Or at least, the address aren't the same even for different structs, using inherited data declarations.
Code:
#include <stdio.h>
#include <stdlib.h>
struct foo {
foo(int x) {
a = x;
}
int a;
int b;
int c;
};
struct bar : foo {
bar(int x) : foo(x) { }
};
struct qux : foo {
qux(int y) : foo(y) { }
};
int main(void) {
struct bar *hope = new struct bar(23);
hope->b = hope->a + 1;
hope->c = hope->a + 2;
struct qux *faith = new struct qux(1);
faith->b = faith->a*2;
faith->c = faith->a*3;
printf("And this is what hope brought : (%d, %d, %d)\n", hope->a, hope->b, hope->c);
printf("And this is why we have faith : (%d, %d, %d)\n", faith->a, faith->b, faith->c);
printf("And just to prove they're different parent classes, %p != %p\n", (void*) &hope->a, (void*) &faith->a);
delete(hope);
delete(faith);
return 0;
}
This has output,
Code:
And this is what hope brought : (23, 24, 25)
And this is why we have faith : (1, 2, 3)
And just to prove they're different parent classes, 0x59f8040 != 0x59f8090
So as you can see, both instances of bar inherit the a, b, c fields listed in foo and that they also inherit from different instances of foo as well. Or at least, the inheritance of one is not directly the other. While they may both inherit fields a, b, c, each a, b, c do not have the same memory addresses.
So basically, I just don't think the code you posted really does anything. Oh wait, that wasn't the point!
It was the vectors! That's right, it was the vectors!
I was curious how you could have a vector of different shapes pointed to by the same type. Like, if vector was of type Shape*, then how could it point to other classes? I'm sorry if I'm a C++ newb. Idk what these crazy CS people do. I think they don't actually know what a vector is but that's not relevant now is it?
Final edit : I know that I'm using "struct" and it really bugs C++ programmers. I also know that structs are by default, public, right? I like that. I don't have to tell it to be public which is nice. Also, any competent C++ programmer knows that a struct declaration is handled different than by gcc. g++ reads it more intelligently than gcc does which is why it's nice. C++ is C with a smarter compiler, is all.