I ask this question because i learned that in programming and designing, you must have a good reason for decisions. I am php learner and i am at a crossroad here, i am using simple incrementation to try to get what im asking across. I am certainly not here to start a debate about the pros/cons of referencing, but when it comes to php, ...
I'm learning how to code in Java after after coming from C. In C I always separated everything into individual functions to make the code easier to follow and edit. I was trying to do this in java but now since I realized that you can't use pointers, I am a bit confused as to what the best way to do this is.
So for example I want to hav...
I have a delegate that modifies an object. I pass an object to the delegate from a calling method, however the calling method does not pickup these changes. The same code works if I pass a List as the object. I thought all objects were passed by reference so any modifications would be reflected in the calling method?
I can modify my cod...
Probably this is not a difficult question, but I am always a little bit confused on how to treat String type as an argument in Visual C++. I have the following to functions:
void function_1(String ^str_1)
{
str_1 = gcnew String("Test");
}
void function_2()
{
String ^str_2 = nullptr;
function_1(str_2);
}
After calling function_1...
The following doesn't work as desired (print 2) because, I guess, the nodes are passed by value even though the vector is passed by reference. How could I fix it?
#include <iostream>
using std::cout;
using std::endl;
#include <vector>
using std::vector;
class Node{
public:
int value;
Node(int);
void createC...
I'm trying to figure out a way to only grab the specific field that pertains to an operation step a unit is in. I have one table with units and their operation step, then I have another table that has a column for each step. I want to pull only the column that relates to that unit's current step.
Here is my attempt but I can't seem to...
I've just found something very strange in PHP.
If I pass in a variable to a function by reference, and then call a function on it, it's incredibly slow.
If you loop over the inner function call and the variable is large it can be many orders of magnitude slower than if the variable is passed by value.
Example:
<?php
function TestCoun...
I'm trying to understand exact C++ (pre C++0x) behavior with regards to references and rvalues. Is the following valid?
void someFunc ( const MyType & val ) {
//do a lot of stuff
doSthWithValue ( val);
}
MyType creatorFunc ( ) {
return MyType ( "some initialization value" );
}
int main () {
someFunc ( creatorFun...
I have a simple VB.Net Form that acts as an interface to a control library with a public API.
One of the API calls takes an Array of UIntegers ByRef:
Public Function Get_Values(source_id As Byte, first_value_address As Byte, number_of_values As Byte, ByRef valuesOut As UInteger()) As Integer
After the call, valuesOut will hold a list...
I am trying to wrap my head about scope in C++. Please consider the following:
class C
{
int i_;
public:
C() { i_ = 0;}
C(int i) { i_ = i; }
C(const C &c) {
i_ = c.i_;
cout << "C is being copied: " << i_ << endl;
}
int getI() { return i_; }
~C() {cout << "dstr: " << i_ << endl;}
};
class D
{
...
I'm very new to C++ and I'm currently learning it. I got a few questions..
What is the differences between void DoSomething(const Foo& foo) and void DoSomething(Foo foo)? If we don't specify & then the instance of Foo will be passed by value ( not reference ). It will be the same as having const + & in argument except no checking at co...
If I want myFunction to take $myVariable and assign to it an instance of SomeClass, I know I can do this:
class SomeClass { }
function myFunction(&$myVariable) {
$myVariable = new SomeClass();
}
myFunction($myVariable);
var_dump($myVariable);
However, I would like to be able to have myFunction operate like this:
class SomeClas...
Sorry to ask, its late and I can't figure a way to do it... anyone can help?
$users = array(
array(
"name" => "John",
"age" => "20"
),
array(
"name" => "Betty",
"age" => "22"
)
);
$room = array(
"furniture" => array("table","bed","chair"),
"objects" => array("tv","radio","bo...
I'm creating a Class.
This class stores user preferences in a Struct.
When creating an instance of the class, I want the client to have the option of creating an instance with no preferences passed in or with a preferences struct passed in.
I can do this with pointers, but I wanted to know how I could do it by passing the preferences...
I thought that if a C# array held reference types it would simply hold references to each of the objects, however the code below tells me otherwise. It appears as if the array is holding a reference to an object of which I thought was set to be garbage collected. I feel like i'm missing something fundamental here. Can anyone tell me w...
Hi,
Does php function parameters pass as ponter to object or as copy of object?
Its very clear in C++ but in php5 I don't know.
Example:
<?php
$dom=new MyDocumentHTMLDom();
myFun($dom);
?>
parameter $dom pass as pointer or as copy?
Thanks
...
Hi!
I'm reading something about overload resolution and I found something that bothers me...In the following code:
int const& MaxValue(int const& a, int const& b)
{
return a > b ? a : b;
}
void SomeFunction()
{
short aShort1 = 3;
short aShort2 = 1;
int const & r2 = MaxValue(aShort1, aShort2); // integral promotion
...
I have an issue when I try to retrieve info through a webmethod. I am using a proxy to call a web service, in that proxy I have an operation which returns data using 'out' parameters.
The server executes the operation succesfully, giving back the parameters properly instanced (I also have checked the soap return message using a traffic...
Is it possible to pass an integer as reference at class initialization and safe the reference?
class Foo {
private int _refVal;
public Foo(ref int val) {
_refval = val; // saves the value, not the reference
}
}
I could use pointers, but then I need an unsafe context.
...
Consider the following function template:
template<typename T> void Foo(T)
{
// ...
}
Pass-by-value semantics make sense if T happens to be an integral type, or at least a type that's cheap to copy.
Using pass-by-[const]-reference semantics, on the other hand, makes more sense if T happens to be an expensive type to copy.
Let's ass...