Questions tagged [reference]

A reference is a value that enables a program to indirectly access a particular datum.

A reference is a value that enables a program to indirectly access a particular datum, such as a variable's value or a record, in the computer's memory or in some other storage device.

See also this Wikipedia entry about references in general, or this one specificially for C++.

48 questions
104
votes
4 answers

How is a Java reference different from a C pointer?

C has pointers and Java has what is called references. They have some things in common in the sense that they all point to something. I know that pointers in C store the addresses they point to. Do reference also store the address? How they are…
Gnijuohz
  • 2,035
  • 4
  • 20
  • 18
31
votes
7 answers

Why are references rarely used in PHP?

I have some C++ knowledge and know that pointers are commonly used there, but I've started to look at PHP open source code and I never see code using references in methods. Instead, the code always uses a return value instead of passing the…
Alexander Cogneau
  • 453
  • 1
  • 4
  • 5
26
votes
4 answers

Why do C++ and Java both use the notion of "reference" but not in the same sense?

In C++ a reference argument to a function allows the function to make the reference refer to something else: int replacement = 23; void changeNumberReference(int& reference) { reference = replacement; } int main() { int i = 1; …
Shivan Dragon
  • 4,583
  • 5
  • 24
  • 31
10
votes
5 answers

Is it possible for two DLLs to conflict , preventing solution to build

Though I have a specific case, but I was wondering about the general situation. Can two DLLs, when added as Reference to a Visual C# project collide with each other to prevent the solution from building? If this is the case, what are the possible…
Shamim Hafiz - MSFT
  • 4,123
  • 7
  • 38
  • 46
9
votes
3 answers

Polymorphic template container: shared_ptr vs reference_wrapper

Assuming we have two classes: class A { ... } class B : public A { ... } Would it be better to write std::deque > container; or std::deque > container; to create a container which is able to contain…
user108376
8
votes
3 answers

What are the pros and cons of using a reference/pointer vs an ID

I'm writing in C++, but this problem applies to any language without GC and even to languages with a GC as well. I have a structure in memory in which I create/add objects. The structure takes ownership of those objects. I should never need to use…
Helloer
  • 253
  • 1
  • 6
8
votes
2 answers

Getting a reference out of a try block

Using C++ I'd like to do something along the lines of: Try to get a reference to something in, say, a map If it throws, then return straight away Otherwise, go and use the reference However because we can't declare a reference object without…
Alex
  • 183
  • 1
  • 4
7
votes
1 answer

What is the term used to describe the number of times a pointer can be dereferenced?

For example, which term completes the sentence "p has 5 ____" in order to describe a situation like int *****p?
7
votes
3 answers

Pointers vs keeping indices of objects stored in a central (associative) array?

Until recently I used to think that it was preferred to reference objects by pointers or references than to keep objects in some sort of a central, authoritative array or dictionary and only keep indices or keys of members of such an array. However,…
gaazkam
  • 3,517
  • 3
  • 19
  • 35
7
votes
3 answers

C++ returning persistent objects

I'm currently trying to learn best practices in C++ after coming from a C# background. I understand that there are three ways of handling objects: By value (objects are copied or moved when passed into and out of functions) By reference By shared…
innova
  • 1,031
  • 1
  • 8
  • 11
7
votes
3 answers

Event-driven vs. 'reference'-driven programming (i.e. in JavaScript)

I haven't been able to find the appropriate terminology to search for content on the web related to what I'm asking, so I'm hoping someone on here can at least point me in the right direction. I'm a fairly senior JavaScript developer, but I have a…
Dan
  • 207
  • 2
  • 3
7
votes
2 answers

How to test functions or the code inside $(document).ready() using Jasmine?

I have multiple functions and a lot of code inside $(document).ready(function()). I am using jasmine to test the functions inside the ready function as well as the code inside ready() but when the test cases inside describe are executed it is not…
makmak
  • 71
  • 1
  • 1
  • 3
7
votes
2 answers

How do document-oriented databases implement references?

In relational world we have Foreign Keys to reference other entities. But how do document-oriented databases like MongoDb, CouchDb, RavenDb implement references among entities? Update. StackExchange related example. We have Question entity and its…
SiberianGuy
  • 4,753
  • 6
  • 34
  • 46
6
votes
3 answers

From a language design perspective, is the reference type in C++ mis-designed

Besides the fact that all primitive types of C++ are copy assignable except the reference type, it also doesn't play well with containers or any other parts of the language where copy-assignable semantics are needed. I personally believe this is…
6
votes
2 answers

Why a function returning by address can not be a lvalue?

Why is it not possible to set a function returning an address while it is possible to set a function that returns a reference. int* returnByAddress() { int x = 20; return &x; } int& returnByReference() { int x = 30; return x; } int…
sk patra
  • 457
  • 2
  • 8
  • 12
1
2 3 4