Tag Info

Hot answers tagged

42

Why? Because, although consistent terminology is generally good for the entire profession, language designers don't always respect the language use of other language designers, particularly if those other languages are perceived as competitors. But really, neither use of 'reference' was a very good choice. "References" in C++ are simply a language construct ...


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. ...


8

A reference is a thing that refers to another thing. Various languages have ascribed a more specific meaning to the word “reference”, usually to “some thing like a pointer without all the bad aspects”. C++ ascribes a specific meaning, as do Java or Perl. In C++, references are more like aliases (which can be implemented via a pointer). This allows pass by ...


7

Not sure what you mean with reference driven programming. From what I gather, you're wondering what the advantages of event-driven programming are as opposed to writing code, and then using a bunch of branches to determine when to call a given method. Before I set off, allow me to be pedantic and point out that: a module can't listen for any event, nor can ...


6

C++11 introduced two new utility classes: std::shared_ptr and std::unique_ptr. If you need to control a resource through multiple handles, then wrap it in a std::shared_ptr, which is a reference-counted smart pointer that cleans up the resource when there are no more pointers to it. std::unique_ptr is designed for single ownership, but it too will ...


6

In the C++ view of the world, a literal does not occupy any memory. A literal just exists. This view makes that there is no address for a pointer to refer to when it would point to a literal and for that reason, pointers to literals are forbidden. Const references are actually the exception here in that they allow apparent indirect access to a literal. ...


4

It largely goes back to Algol 68, and partly to a reaction against the way C defines pointers. Algol 68 defined a concept called a reference. It was pretty much the same as (for one example) a pointer in Pascal. It was a cell that contained either NIL or the address of some other cell of some specified type. You could assign to a reference, so a reference ...


4

In C++, literals exist only in the compiler. They are used in expressions, assignments and initialisations. The value of a literal may be found in the running program if it has been used to initialise a variable or temporary, but the literal itself is not. A name that is a reference to a literal has meaning, because a reference is a value, so that wherever ...


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 ...


3

Not 100% sure I know what you're asking. But, I get the sense you're at a point where event-driven programming doesn't feel "real" enough -- or like you're at the mercy of someone else's event system. Or like your application isn't really "doing" anything. Or like it's just a bunch of disparate methods that you're feeding another application. So. Suppose a ...


3

in your code, domready calls an annonymous function. If we had a reference to this function, we could call it. var onReady = function(){ testVar = true; } $(document).ready(onReady); and in your tests it("Test Alert Box Message For Change Modal", function() { var testVar = false; onReady() ; expect(testVar).toEqual(true); }); your code ...


2

To start off your code is broken. Returning a reference or the address of a local variable is returning garbage. Never do this. Here I've rewritten your example to return something real. int xByAdress = 20; int xByReference = 30; int* returnByAdress() { return &xByAdress; } int& returnByReference() { return xByReference; } int main() { ...


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

It looks like Bouncy Castle has a NuGet package. You could set up your VS2013 solution for package restore, and then reference Bouncy Castle through NuGet. By doing so, you don't actually store the referenced files in your repository at all, just the NuGet reference. Then, when somebody else builds your project, the package restore process will download the ...


1

From a C++ language standpoint, your code is fine. As a C++ user, it depends very much on the semantics of struct A if I would expect it to maintain a reference/pointer to B, make a copy of it or to use the constructor parameter only in the constructor. My general expectations are (all unless indicated otherwise): If a parameter is passed by (smart) ...


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 ...


1

No, they are not the same bars, since you are calling new. Also I don't see $bars being used anywhere in wireFoosAndBars. Use the exact "associated" instances from $bars when constructing the new collection and they will be the same objects. You are correct in that clone is the only way to make a copy of an object. Modifying an object's properties, no ...



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