Tag Info

Hot answers tagged

9

Firstly, you probably shouldn't implement a container class. 95% of the time you should one included in the standard library. If you just want to learn, or are in the 5%, carry on. If you are defining a template, leave the decision up to your users. You users can use: Stack<Foo> if they want by value. Stack<Foo*> if they want by pointer. ...


3

My question is: what is the preferred approach in C++? Is there a preferred approach? Which approach should I normally take when implementing 'container' classes? In C++ you can keep objects by: value reference pointer smart pointer (std::unique_ptr, std::shared_ptr, YourPointerClass). (you didn't mention the last two). Each of these is valid for ...


2

The basic idea behind open-source licensing is that anyone who has (legally) obtained a copy of the source code also has the right to make modifications and the right to distribute the modified or original work. The main difference between open-source licenses is in what rights you must give away when re-distributing the work. With one or two exceptions, ...


2

To extend on comments, your assertion On some platforms references have to be at least 64 bit, so it cannot rely on usually atomic 32 bit word operations is not quite correct. Yes, on some platforms your references will be 64 bit, but that's (universally?) because their word size is 64 bit. After all, if the word size didn't match your address size, ...


2

Preparing my flame-retardant suit, as I feel some bias must be present in any answer to this question. First, I would like to note that I work within the embedded world, so RAII and stack allocation are generally the way to go. In almost any circumstance, I see passing something in by reference as a good idea because of the obvious reason: it can't be NULL. ...


1

If I'm writing code on the client side, I don't know which of the variables I pass to a function might be changed and which I can expect to remain the same without an explicit knowledge of the parent function declaration. This is as it should be. When you call an API, you should know what you are calling and why. You should also know what the function ...



Only top voted, non community-wiki answers of a minimum length are eligible