|
|
Subscribe / Log in / New account

What exactly is an object?

What exactly is an object?

Posted Feb 25, 2025 10:11 UTC (Tue) by Sesse (subscriber, #53779)
In reply to: What exactly is an object? by tialaramex
Parent article: Slabs, sheaves, and barns

C++ does, in a sense, have this; it's just that the syntax is different. The philosophy is simple: Something can be a part of the class' interface without being a method (or member function, in C++ parlance). E.g., operator==(const Foo&, const Foo&) can be defined well outside of Foo, and then follows the normal rules for free functions. Something as simple as void whatever(const Foo&) can be seen a part of Foo's interface; in fact, it is commonly preferred if you can implement it not as a friend.

Of course, adding _data members_ to another class from the outside would be nearly impossible in C++'s compilation model (which it, of course, inherited from C).


to post comments

What exactly is an object?

Posted Feb 25, 2025 20:09 UTC (Tue) by tialaramex (subscriber, #21167) [Link] (1 responses)

It doesn't seem useful to say "It's like method syntax except without the same syntax". That's just not method syntax. Some languages have Unified Method Call Syntax, so _all_ functions in the language which take at least one argument can be used as method calls. Rust only has the other side of that coin, all the methods in the language can also be treated as free functions with an extra argument - but not vice versa.

C++ ADL which maybe you were also gesturing at is just a mess. Your whatever function is indeed treated by C++ as if it's "part of Foo's interface" but only when it was defined in the same namespace so that ADL will find whatever when it is looking up Foo. This causes weird hard to understand issues in real world C++ software because what foo(bar) means will depend on the context in which you wrote it in non-obvious ways, as a result "turning off ADL" via arcane tricks is often needed & there have been attempts to reform ADL or to add explicit "No ADL please" features to the language.

I was serious about that docbug, who do I raise this with? I'd rather raise it as a bug rather than sending a patch because I'm certain those answering the bug ticket will know more than I do about kmalloc

What exactly is an object?

Posted Feb 27, 2025 9:28 UTC (Thu) by aviallon (subscriber, #157205) [Link]

You can simply open a bug on the kernel bugzilla


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds