5 ms·
Hmm, not sure what you mean. In the body of a function there is one class dict available. On the other hand there is one vtable per object, typically.
by tome 6y ago
Hmm, not sure what you mean. In the body of a function there is one class dict available. On the other hand there is one vtable per object, typically.
- richardwhiuk 6y agoIn C++ and Rust, there's a single vtable per class (trait), not per object. (This is basically why Rust doesn't support multi-trait types (e.g. &dyn Debug + Clone)
- estebank 6y agoYou can accomplish the same behavior by having a marker trait: trait Foo: Debug + Clone {} Edit: No you can't, because `Clone` requires `Sized`, which means you can't make a trait object of `Foo`. https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=252fbe402fe80be54816667afc5c62f3 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- ImprobableTruth 6y agoI don't know of a single language that has a vtable per object. What would even be the point? Edit: Assuming we're talking about objects that can be grouped into some sort of 'classes'.
- gpderetta 6y agoIsn't python __dict__ pretty much a per-object vtable?
- tome 6y agoI see I wasn't clear enough. With object-style polymorphism, the vtable is looked up on the object, using some means or other. With typeclass-style polymorphism, the "vtable" is (effectively) looked up on the type. Perhaps gpderetta said it better: https://news.ycombinator.com/item?id=23537639 https://news.ycombinator.com/item?id=23537639