Похожие чаты

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

know what I mean.

21 ответов

65 просмотров

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

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

How’d u define polymorphism in C/Cpp?

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

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

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

with bounded you can use a tagged union

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

Not sure what u mean by bounded

Mahdi
Not sure what u mean by bounded

How many possible different kinds of things are there?

Mahdi- Автор вопроса
Mahdi- Автор вопроса
Mahdi
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

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

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

а через ESC-код ?
Alexey Kulakov
29
30500 за редактор? )
Владимир
47
Чёт не понял, я ж правильной функцией воспользовался чтобы вывести отладочную информацию? но что-то она не ловится
notme
18
У меня есть функция где происходит это: write_bit(buffer, 1); write_bit(buffer, 0); write_bit(buffer, 1); write_bit(buffer, 1); write_bit(buffer, 1); w...
~
13
any reference of this implementation?
BitBuddha
29
Ⓐrtto, [4/23/24 7:02 PM] Please explain more fully how it is not working exactly, and what are the steps you are taking, and what error messages come or what happens. Ⓐrtto, ...
Ezza Kezza
2
sounds like people have lost their kaspa on tradeogre... does this mean tradeogre not trustworthy?
Ezza Kezza
15
Страшнейшая правда про списки ЦБ. С первых дней жизни P2P сферы, молодые человеки, начитавшись законодательной базы и "внутренних" документов, решили, что им противостоит сер...
Foxcool
3
Недавно Google Project Zero нашёл багу в SQLite с помощью LLM, о чём достаточно было шумно в определённых интернетах, которые сопровождались рассказами, что скоро всех "ибешни...
Alex Sherbakov
5
So much speculation in the last week. So much volatility in price. This is because Hedera has a GC that isn't using the network it's governing. Why aren't people asking why a...
Summit Seeker R
9
Карта сайта