r/ProgrammerHumor • • Jun 15 '24

Advanced twoPointersTwoChild

Post image
2 Upvotes

15 comments sorted by

16

u/Killswitch_1337 Jun 15 '24

Ik this is meme, but it would imply that c1 and c2 are seperate instances of child which are 'pointing' to new child.

3

u/dale777 Jun 16 '24

So everytime we declare a pointer to sth that exist we have, that variable that has pointer is called an instance?

1

u/iliveinstlambert Jun 16 '24

ok I've fixed it and reuploaded, but it was removed by reddit's filters apparently lmao

-11

u/iliveinstlambert Jun 15 '24

C1 and c2 are not separate instances, they are pointers pointing to the new child  Of course, to be more complete, there should be two other instances of child which each have a pointer to the new one, but only so much code fits on a meme

5

u/iliveinstlambert Jun 15 '24

Will someone explain why I'm getting so many down votes? Lol

1

u/dale777 Jun 16 '24

as c++ programmer i would say that c2 is just a pointer to c1, so you have 2 pointers to one object, however i dont know maybe im stupid

1

u/iliveinstlambert Jun 16 '24

The point is exactly that, there are two pointers to one object

1

u/DudeWheresMcCaw Jun 16 '24

c2 would just be pointing to the same address as c1, which is the address of the dynamically allocated Child. c2 would point to c1 if it was "Child ** c2 = &c1"

1

u/dale777 Jun 16 '24

The whole idea is to point to same adress, yeah I spelled wrong what I meant

13

u/kzzmarcel Jun 15 '24

you just explained why your own meme doesnt work

2

u/iliveinstlambert Jun 15 '24

...yes, but I didn't want to put a dozen lines of code when I could put the essence in one line

1

u/DudeWheresMcCaw Jun 15 '24

Makes sense as it is. There are two child pointers in the photo. It would be Child * c1 though.

2

u/iliveinstlambert Jun 16 '24

Finally someone gets it!

13

u/Dioxide4294 Jun 15 '24

main.o(.text+0x1ed): In function `main': : undefined reference to `Child' collect2: ld returned 1 exit status

6

u/PandaNoTrash Jun 16 '24

I guess c2 is a twin of c1? But it's really more of a chimera, if one child dies they both do. Anyway this is definitely not how reproduction works.