- "Bjarne Stroustrup announces C++ Core Guidelines" - 3 Updates
- "Bjarne Stroustrup announces C++ Core Guidelines" - 1 Update
- Question about "// ::operator delete(pt);" - 2 Updates
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Oct 02 05:49AM +0200 > Private types and functions can be placed with private data. > --------------------------------------------- > I suggest to make the data members first. I also disagree with the rule, it seems non-sensical, and yes, like you, for common use of the code (as opposed to documentation) I find it better to have data first. And generally, I find it better to declare things before they're used. That's recognized as a sound rule in almost every other context, and it doesn't cease to be a good idea in C++. For a long time I tried to group things logically, e.g. accessors followed by mutators, but it turned out to have too many exceptions, and I now think that it's more important to e.g. place `const` and non-`const` variants of a method together. Unless special accessibility is needed, at the end of a class I place (1) destructor, if any, and (2) constructors, with the standard ones first. Cheers, - Alf |
Vir Campestris <vir.campestris@invalid.invalid>: Oct 02 09:50PM +0100 On 30/09/2015 23:47, Stefan Ram wrote: > constructor when one has not yet read their declarations, > for example? The data members are the key to understanding > the implementation. Therefore, they must be declared first. I disagree. When reading the class header chances are you want to use it - so you are interested in the interface. Which is the public stuff - so it comes first. The data is an implementation detail, and I'm happy to hide it. Andy |
Jorgen Grahn <grahn+nntp@snipabacken.se>: Oct 02 09:40PM On Fri, 2015-10-02, Stefan Ram wrote: > When one wants to use a class, one reads its documentation > (the documentation can be generated using Doxygen or be > written as a separate document such as cppreference). I don't -- like Vir I read the header file to see the API. And it seems those C++ Core Guidelines aim to support us, which is nice. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o . |
ram@zedat.fu-berlin.de (Stefan Ram): Oct 02 09:19PM >When reading the class header chances are you want to use it - so you >are interested in the interface. Which is the public stuff - so it comes >first. When one wants to use a class, one reads its documentation (the documentation can be generated using Doxygen or be written as a separate document such as cppreference). The separation between documentation (outside) and implementation (inside) of an object is one of the most important achievement of sound software engineering. (Needless to say that this implies that there must be documentation at all for any professional class.) Since C++ class specifiers often contain the implementation of (inline) private parts, they cannot double as documentation for the public parts. Also, documentation needs a lot of English text that usually is not part of C++ class specifiers (unless one is using Doxygen, which I'd recommend). One reads the source code when one wants to understand the implementation. |
fl <rxjwg98@gmail.com>: Oct 02 11:15AM -0700 Hi, I see a code snippet online, see below please. I don't understand the comments after 'delete pt;'. If I run the code, message "MyClass destroyed" is printed out. In stead, if I run: ::operator delete(pt); the above message does not print out. Then, my question is why there is such a difference. '::operator delete(pt);' is from C++ standard library? Thanks for help. /////////////// #include <iostream> // std::cout struct MyClass { MyClass() {std::cout <<"MyClass constructed\n";} ~MyClass() {std::cout <<"MyClass destroyed\n";} }; int main () { MyClass * pt = new (std::nothrow) MyClass; delete pt; // implicitly calls ::operator delete(pt) return 0; } |
Bo Persson <bop@gmb.dk>: Oct 02 08:37PM +0200 On 2015-10-02 20:15, fl wrote: > delete pt; // implicitly calls ::operator delete(pt) > return 0; > } Yes, "delete pt" does more than just calling operator delete. I first also calls the destructor for your object. Bo Persson |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment