Похожие чаты

Do u call the use of “void*” polymorphism? If u

know what I mean.

21 ответов

38 просмотров

Definitely not. Polymorphism happens when the compiler does stuff for you under the hood and you as a developer just have to understand the idea of it to get it to work. Use of void* on the other hand requires you as a developer to write the code yourself and also understand the idea of polymorphism to get it to work right.

It can be *part of* polymorphism I guess

VD
Definitely not. Polymorphism happens when the comp...

polymorphism is still polymorphism when done manually

Raymond- Автор вопроса
Thomas
It can be *part of* polymorphism I guess

How’d u define polymorphism in C/Cpp?

Raymond- Автор вопроса
Raymond
Psudocode?

struct MyInterface { void *data; void (*doThing)(void *); } x->doThing(x->data);

Raymond- Автор вопроса
Raymond
This is exactly what I had in mind

with bounded you can use a tagged union

Raymond- Автор вопроса
Thomas
with bounded you can use a tagged union

Not sure what u mean by bounded

Raymond
Not sure what u mean by bounded

How many possible different kinds of things are there?

Raymond- Автор вопроса
Raymond- Автор вопроса
Raymond
How many different types you mean?

This can be like: "4" "I'll add like 10-ish, but I'll know at compile time" "It's a plugin system, so it's only known at runtime, however many plugins the user needs to load"

I call it downcasting.

Thomas
polymorphism is still polymorphism when done manua...

Polymorphism as a concept defines subtyping which by definition is not something that is allowed in C. So you can't then say using void* pointers to simulate subtyping is polymorphism in the strictest sense. As long as a language does not support subtyping, it can't be called polymorphism. Moreover using void* pointers to cast from one type to another unrelated type is Undefined Behavior according to the C standard. So even if you see the behavior you expect on your implementation, it is not guaranteed to happen across all implementations. So this behavior is indeed undefined behavior and is therefore no where close to the idea of polymorphism

VD
Polymorphism as a concept defines subtyping which ...

But you're never casting from one type to another

VD
Polymorphism as a concept defines subtyping which ...

https://en.m.wikipedia.org/wiki/Polymorphism_(computer_science)

Thomas
https://en.m.wikipedia.org/wiki/Polymorphism_(comp...

I'm not talking about subtype polymorphism

Похожие вопросы

Обсуждают сегодня

а зачем этот вопрос для удаления из чата?
Mёdkinson Medvezhkin
63
using next image component with s3 image: "url" parameter is valid but upstream response is invalid code: <Image fill src={s...
Fasil
3
Эх кто-то пришел и весь праздник испортил :( You need complex FBX scene importing setup to change things on import? good luck with that. You need navigation and pathfinding? g...
Serg Gini
5
Friends, how can I find my Wazirx wallet address?
Silm Silm
31
Всем привет! Подскажите. Я написал приложение на Delphi 10.2 Tokyo под Windows 10. И передо мной стал вопрос о том чтобы сделать это приложение кроссплатформенным (под Linux и...
Дмитрий Завгородний
24
Какого хера? /Sources/App/Modules/User/Models/UserLinkApple.swift:21:20: warning: stored property '_id' of 'Sendable'-conforming class 'UserLinkApple' is mutable @ID(...
Alexander Sherbakov
14
My 7 year old daughter recognizes the Bitcoin symbol and knows it's currency. What are the top ,3-5 most basic important concepts to convey to a kid about BCH? I started with ...
Big Hair
24
How many Cashfusion server now?
Crypto life
22
But I'm wondering how exactly we can increase our chances of winning. Do you think it's just a matter of luck, or are there specific actions we need to take to qualify?
Luqman Ayman
12
Кто знает локации, где можно машину красиво отфоткать?
Lalalashechki Lalala
23
Карта сайта