I sent a reference to a bool object, and I modified it within a method. After the method finished it's execution, the value of the bool outside the method was unchanged.
This leads me to believe that Python's bools are passed by value. Is that true? What other Python types behave that way?
...
OK, so I'm trying to use S4 classes to build a very complex object, with slots including a half-dozen matrices, a few lists, and probably a kitchen sink or two in there. The object is initialized by referring to and unpacking a configuration object which I've already defined. It's easy enough to define the class with setClass(), but I'm ...
In .NET, strings are immutable and are reference type variables. This often comes as a surprise to newer .NET developers who may mistake them for value type objects due to their behavior. However, other than the practice of using StringBuilder for long concatenation esp. in loops, is there any reason in practice that one needs to know th...
I know there are few question about const correctness where it is stated that the declaration of a function and its definition do not need to agree for value parameters. This is because the constness of a value parameter only matters inside the function. This is fine:
// header
int func(int i);
// cpp
int func(const int i) {
return...
I think of DataGridView's as being memory hogs. Is it better to pass by value a datagridview or by reference? Should it even be passed at all?
...
Some time ago I posted a question about what questions should a good javascript coder be able to answer. Meder pointed out the following question:
The following code makes clicks on any "a" element to alert(-1) due to the fact that "i" is hold in the onclick function as a reference and not as a value:
<a href="#">text</a><br><a href="...
Should a C++ (implicit or explicit) value constructor accept its parameter(s) by value or reference-to-const, when it needs to store a copy of the argument(s) in its object either way?
Here is the shortest example I can think of:
struct foo {
bar _b;
foo(bar [const&] b) // pass by value or reference-to-const?
: _b(b) { ...
class mystring {
friend ostream& operator<<(ostream &out, const mystring ss) {
out << ss.s;
return out;
}
private:
string s;
public:
mystring(const char ss[]) {
cout << "constructing mystring : " << ss << endl;
s = ss;
}
};
void outputStringByRef(const mystring &ss) {
cout << "outputStri...
In my code I'm instantiating a legacy Delphi object through a COM interface.
This class needs to be instantiated many times, so in order to lower the overhead of instantiating it I cache it at a point where 70% of all the calls have the common resulting object.
However, when I alter the object after it is cached, the changes are persi...
We've created a caching layer to our J2EE-application. In this instance we use Ehcache. This has created a few challenges.
Let's take this example.
OrderItem orderitem = cache.getOrderItemByID("id");
OrderItem old_orderitem = cache.getOrderItemID("id");
orderitem.setStatus(1);
old_orderitem.setStatus(2);
If we're not carefull, any ...
We have a C++ library which uses a struct containing an STL vector of structs, like so:
struct Params
{
// values...
}
struct Settings
{
std::vector<Params> m_params;
// values...
}
I'm writing a CLI wrapper for the library, and I want equivalents for the above struct types. I had been thinking about using a List as the...
From the lectures notes of a course at university, on "call-by-value":
void fun(int *ip)
{
*ip =100;
}
called by
int n=2;
int *np;
np =
fun(np);
would change the value of n to 100.
When we say "int *ip", what exactly do we mean? A pointer of type integer? If so, when we call fun() with np as its argument, shouldn...
Hello everyone, this question has been bugging me for a while, so i thought i'd ask.
Is there a case where pass-by-reference is more expensive than pass-by-value in C++? If so, what would that case be?
Thanks.
...
I am new to C++ programming, but I have experience in Java. I need guidance on how to pass objects to functions in C++.
Do I need to pass pointers, references, or non-pointer and non-reference values? I remember in Java there are no such issues since we pass just the variable that holds reference to the objects.
It would be great if yo...
I'm just learning c++, and coming from c, some function calls I'm seeing in the book confuse me:
char a;
cin.get(a);
In C, this couldn't possibly work, if you did that, there would be no way to get the output, because you are passing by value, and not by reference, why does this work in c++? Is referencing and dereferncing made implic...
I got the answer NO! Because passing by value and passing by reference looks identical to the caller.
However, the code below compiles right
class A {
public:
void f(int i) {}
void f(int& i) {}
};
But when I try to use it, there is compile error.
int main () {
A a;
int i = 9;
int& j = i;
a.f(1);
a.f(i);
a.f(...
Are arrays passed by default by ref or value?
Thanks.
...
Here is a simplified version of something I'm trying to run:
for (var i = 0; i < results.length; i++) {
marker = results[i];
google.maps.event.addListener(marker, 'click', function() {
change_selection(i);
});
}
but I'm finding that every listener uses the value of results.length (the value when the for loop terminates)....
Why does the following code return 100 100 1 1 1 and not 100 1 1 1 1 ?
public class Hotel {
private int roomNr;
public Hotel(int roomNr) {
this.roomNr = roomNr;
}
public int getRoomNr() {
return this.roomNr;
}
static Hotel doStuff(Hotel hotel) {
hotel = new Hotel(1);
return hotel;
}
public static void main(String arg...
This one has been driving me mad! I have a struct:
typedef struct{
int a;
}myStruct;
Then I have:
myStruct tempStruct;
I am trying to pass the struct to a class method whose implementation is:
- (void) myFunc:(struct myStruct)oneOfMyStructs{};
I call the method like so:
[myClass myFunc:(struct myStruct)tempStruct];
The com...