Java/C# language lawyers like to say that their language passes references by value. This would mean that a "reference" is an object-pointer which is copied when calling a function.
Meanwhile, in C++ (and also in a more dynamic form in Perl and PHP) a reference is an alias to some other name (or run-time value in the dynamic case).
I'm...
I'm having trouble figuring out how to pass strings back through the parameters of a function. I'm new to programming, so I imagine this this probably a beginner question. Any help you could give would be most appreciated. This code seg faults, and I'm not sure why, but I'm providing my code to show what I have so far.
I have made this ...
I am not sure if I have asked the question correctly. Please correct me if I am wrong.
Anyways, we would like to use a variable's value on a different phases of the page's life cycle.
So for example,
public partial class TestUserControl: UserControl{
public TestUserControl(){
Objects = new List<object>(){
Prope...
Hi,
I am trying to implement an algorithm I found in C# in javaScript and am facing some issues.
Basically I am finding it difficult to pass by reference in JS. I have broken down the problem I have to the following example code, let say you have the following C#:
using System;
using System.Collections.Generic;
using System.Linq;
usin...
I am having this problem which I can't seem to get my head around. I would like some help on this.
@user.update_languages(params[:language][:language1], params[:language][:language2], params[:language][:language3])
lang_errors = @user.errors
logger.debug "--------------------LANG_ERRORS----------101-------------" + lang_erro...
I know this is a really long shot, but I figure I'd ask: Is there a way to to find the names of the variables passed as parameters in a function call?
Assuming I have:
function test(tmp1, tmp2) {
// ...
}
var a;
var b;
test(a, b);
I'd like to get an array like so: [a, b]. Strings would also be acceptable: ["a", "b"].
I do not w...
Seemingly something of a misnomer, as pass by reference is deprecated in PHP 5.3... anyway, what I'm trying to do is write a unit test framework using reflection, that allows you to pass arguments to a method which requires a reference. e.g.
class Bar {
function TestMethod($arg1, &$result) {
$result = 'hello';
return...
Hey Guys,
I am having an issue modifying a smarty variable by reference. Here is what I am trying to do:
class foo {
$property;
public function getProperty(){
return $this->$property;
}
public function index(&$smarty){
$smarty->assign('test',$this->getProperty());
}
}
$smarty = new Smarty();
$foo ...
Is it possible to create a PHP function that takes a variable number of parameters all of them by reference?
It doesn't help me a function that receives by reference an array of values nor a function that takes its arguments wrapped in an object because I'm working on function composition and argument binding.
Don't think about call-tim...
void outputString(const string &ss) {
cout << "outputString(const string& ) " + ss << endl;
}
int main(void) {
outputString("constant tranformed to reference argument");
//! outputString(new string("abc")); new only return pointer to object
return 0;
}
Since its prohibited to create temporary object reference transform...
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...
Consider the functions sort and array_reverse.
Why does one modify the variable passed, whereas the other return a new version?
$a = array(3, 1, 2);
sort($a);
// $a === array(1, 2, 3)
array_reverse($a);
// $a === array(1, 2, 3)
sort could just as easily been written to return a modified copy of the argument, and vice-versa for arra...
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 ...
I have an application that uses ehcache for cache (but I think this problem is framework-agnostic), with a method interceptor so basically if I mark my method for caching something like this happnes:
public Object invoke(MethodInvocation mi) throws Throwable {
Object result = cache.get(key);
//key comes from MethodInvoc...
This is the test and the response I get. I think this could be problematic and should throw an error or a notice but I cannot understand why is tolerated.
<?php
$test = array( 0 => 'test', 1=> &$test );
var_dump( $test );
// array(2) { [0]=> string(4) "test" [1]=> &array(2) { [0]=> string(4) "test" [1]=> &array(2) { [0]=> s...
I have a questing around such staff.
There is a class A which has a object of type class B as it's member. Since I'd like B to be a base class of group of other classes I need to use pointer or reference to the object, not it's copy, to use virtual methods of B inside A properly. But when I write such code
class B
{public:
B(in...
I have a class "skImage". This class has a private variable (with a public property that exposes it)
private Image _capturedImage;
the constructor of this class looks like:
public skImage(Image captured) {
_capturedImage = captured;
}
It also has the following method:
public bool Invert() {
Bitm...
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...
Okay...I have a situation where a C# .dll is a singleton. Now, what I want to be able to do is when the singletonInstance is instantiated be able to provide a reference to any other applications that may start. So, I looked up NamedPipes and that would work - except for one thing, this must be cross-platform, or platform independent. I h...