Questions tagged [reference]
A reference is a value that enables a program to indirectly access a particular datum.
51 questions
0
votes
2
answers
350
views
Why do you need to use pass by reference in C++ to change the value of the arguments inside the function?
I'm new to coding and am currently trying to learn C++ myself. I just learned about function parameters and pass by value vs pass by reference. Everywhere I read, they say that one of the reasons pass ...
-2
votes
1
answer
376
views
Decoupling thirty dependencies for projects that reference each other in a sequence
I am working on a simple interface to SharePoint via Graph API. I have created a project that references Azure.Core, Azure.Identity, Microsoft.Graph, and other dependencies required to make calls via ...
4
votes
2
answers
2k
views
Reference variable vs Alias
When I started programming, I learned what Pointers are in C++. In Java, references are variables which hold the address of an object. So conceptually it's a pointer, without the ability to directly ...
11
votes
3
answers
3k
views
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 ...
5
votes
4
answers
2k
views
Value/reference type, object and semantics
What are the relationships between these pairs of concepts:
value/reference type;
value/reference object;
value/reference semantics?
For the first pair of concepts, it seems to me that an object of ...
3
votes
1
answer
3k
views
C++ API design: using references vs smart pointers in a getter API
I'm trying to design an API for an object manager that registers and retrieves different related objects. When I want to retrieve an object, I can query it by its object id. I'm wondering if I should ...
0
votes
2
answers
402
views
How to validate reference use?
I use "reference" term here like in C++ world, not like in C# (for example). I use non-C++ syntax on purpose -- this is general question, not about this particular implementation.
Starting something ...
1
vote
1
answer
3k
views
Object exists as long as referenced somewhere, explicit dispose not helping? [closed]
I am bit puzzled as for why this does not throw an exception - I believe the CLR does not delete the object because there is a reference to it?
static void Main(string[] args)
{
...
9
votes
2
answers
6k
views
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 ...
1
vote
2
answers
1k
views
Passing by refernce
I am trying to understand the ideas of pointers and references in C++. I am stuck with the following, what would be the specific behaviour in this case? I have a class like this:
class MyClass{
...
1
vote
3
answers
647
views
C++ vs Java: Pointing to Objects
In Java:
private State current_state;
As "State" is a superclass, I can then assign subclass objects to current_state, effectively making current_state point to a different object:
current_state = ...
-1
votes
1
answer
375
views
In which cases and examples String in Java is not immutable? [duplicate]
If Strings are immutable in Java, why is the output of this code 2GB, instead of 1GB?
class Laptop {
String memory = "1GB";
}
class Workshop {
public static void main(String args[]) {
...
6
votes
2
answers
7k
views
Use a hash character or a dot when referring to methods and fields in software documentation? [closed]
Assuming I have this class (Java code only for the sake of example):
class Person {
private String name;
public void setName(String name) {
this.name = name;
}
}
When I write ...
10
votes
3
answers
7k
views
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<shared_ptr<A> > container;
or
std::deque<reference_wrapper<...
3
votes
3
answers
10k
views
What should I do in C++ when implementing a container class: storing objects by value or by reference?
I'm new to C++, coming from Java.
In Java, all variables (except for primitives) are essentially pointers. They hold the address of whatever they're 'holding'.
So any Java data structure stores it's ...
4
votes
3
answers
1k
views
Why is C++ "this" poorly designed?
For every a and b which are non-const pointers of the same type, you can do a = b;, right?
Inside non-const member functions the this keyword exists, which is a non-const pointer. So logicaly if b is ...
2
votes
1
answer
113
views
Do objects maintain identity under all non-cloning conditions in PHP?
PHP 5.5
I'm doing a bunch of passing around of objects with the assumption that they will all maintain their identities - that any changes made to their states from inside other objects' methods will ...
0
votes
1
answer
413
views
How do I properly add a reference from my Github project to someone elses in VS2013 on Windows 8?
I need to reference the latest version of Bouncy Castle in a project I intend to publish to Github.
In my first posting of the code to Github, someone complained that I downloaded the entire Bouncy ...
-1
votes
2
answers
985
views
Difference between a pointer and a reference? [duplicate]
In Java and other high-level languages, a reference leads to an object.
In C++, as far as I know, a pointer can also lead to an object.
So what's the difference between a reference leading to an ...
3
votes
3
answers
8k
views
Why are pointers to literals not possible?
Reference to a literal is possible only if the reference is declared as constant.
But why is a pointer to a const object not possible in case of literals?
i.e.
int const& ref = 5;//
But why is ...
7
votes
3
answers
4k
views
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 ...
7
votes
2
answers
14k
views
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 ...
32
votes
7
answers
18k
views
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 ...
107
votes
4
answers
73k
views
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 ...
7
votes
2
answers
3k
views
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 ...