标签: reference

如何在perl中取消引用此哈希?

#!/usr/bin/perl
use Data::Dumper;

sub giveMeARef {
    my %hash = %{$_[0]};

    print "arg: ", Dumper($_[0]);
    print "deref: ", Dumper(%hash);
}

my %hash = ( "a" => (1,2,3), "b" => (3,4,5));

giveMeARef(\%hash);
Run Code Online (Sandbox Code Playgroud)

这会产生以下输出:

arg: $VAR1 = {
          '2' => 3,
          '4' => 5,
          'a' => 1,
          'b' => 3
        };
deref: $VAR1 = 'b';
$VAR2 = 3;
$VAR3 = '2';
$VAR4 = 3;
$VAR5 = 'a';
$VAR6 = 1;
$VAR7 = '4';
$VAR8 = 5;
Run Code Online (Sandbox Code Playgroud)

我试着按照如何取消引用已传递给子例程的Perl哈希引用中的示例

但我相信因为我的哈希更复杂,所以对我来说不合适.我如何回到我传入的原始结构?

perl hash reference subroutine

0
推荐指数
1
解决办法
75
查看次数

将ref关键字与引用类型参数一起使用有什么好处?

作为开发人员,如果不更改引用所指向的参数类型参数,则使用ref关键字将该参数传递给方法,我会获得什么

我已经读过两个,带有引用类型参数的ref关键字C#中引用类型变量的"ref"有什么用?和其他一些人.我知道这个问题已经被问过很多次了.我相信我在问一个独特的问题.如果你认识其他的wize,请随时记下我的问题.

简单的课程:

public class Person
{
    public Person(string first, string last)
    {
        FirstName = first;
        LastName = last;
    }

    public string FirstName { get; set; }

    public string LastName { get; set; }

    public override string ToString()
    {
        return string.Format("{0} {1}", FirstName, LastName);
    }
}
Run Code Online (Sandbox Code Playgroud)

使用关键字'ref'传递表单:

public partial class Form2 : Form
{
    private Person _person;

    public Form2()
    {
        _person = new Person("John", "Doe");
        InitializeComponent();
    }

    protected override void …
Run Code Online (Sandbox Code Playgroud)

c# reference ref

0
推荐指数
1
解决办法
511
查看次数

在switch语句中通过引用返回

我想通过引用返回到交换机内部的变量来返回,例如:

sometype & getbar();

void foo() {
        switch ( {statement} ) {
        case {statement}:
            sometype & handle = getbar();
        ...
Run Code Online (Sandbox Code Playgroud)

但我收到编译器错误:

'case'标签跳过'identifier'的初始化

'default'标签跳过'identifier'的初始化

它似乎不可能这样做:

void foo() {
        sometype & handle;
        switch ( {statement} ) {
        case {statement}:
            handle = getbar();
        ...
Run Code Online (Sandbox Code Playgroud)

因为引用变量需要初始化.

有没有办法保持switch语句?

c++ syntax reference switch-statement c++11

0
推荐指数
1
解决办法
209
查看次数

为什么我的GroupBy - > SelectMany例程正常工作?

我6个多月前自己写了这个,现在我记不清它为什么会这样...

我有以下代码:

var grouped = alleSkjema.GroupBy(q => q.OrgID);
var newGroupList = grouped.Where(q => q.Count() < 4).SelectMany(p => p).ToList();
newGroupList.ForEach(p => p.OrgID = u.tre.First().orgid);
Run Code Online (Sandbox Code Playgroud)

哪里alleSkjemaIEnumerable<T>一些性质.OrgID是一个部门ID,T在此上下文中是一个人.

我在上面的代码中所做的是将属于少于4人的部门的每个人分组到他们自己的小组中.这是出于匿名原因,对解决方案而言并不重要.

接下来会发生的是,只有上面的三行,alleSkjema被修改,我无法弄清楚原因.我猜可变性在屁股上咬我?我以为我需要在alleSkjema收集的最后一行做我正在做的事情以获得预期的结果.是否以newGroupList某种方式包含对alleSkjema集合的引用?

c# reference

0
推荐指数
1
解决办法
41
查看次数

我可以使用对派生类实例的基类引用初始化派生类引用吗?

我有以下内容:

class A { ... };
class B : public A { ... };

// ...

B b;
const A& aref(b);

// ...

const B& bref(aref);
Run Code Online (Sandbox Code Playgroud)

当我编译时,我得到:

no suitable user-defined conversion from "const A" to "const B" exists
Run Code Online (Sandbox Code Playgroud)

现在,如果这些是指针而不是引用,我会使用

bptr = dynamic_cast<B*>(aptr);
Run Code Online (Sandbox Code Playgroud)

但参考文献没有.我该怎么办?切换到指针?别的什么?

c++ inheritance dynamic-cast reference downcast

0
推荐指数
1
解决办法
86
查看次数

重载运算符不起作用的复合语句(C++)

我在c ++中创建了一个类Matrix,但在测试中,我发现了类似的语句

cout << M1;    //M1 is object of class Matrix
Run Code Online (Sandbox Code Playgroud)

正在工作,但其他人喜欢

cout << M1 + M2;    //M1 and M2 of class matrix
Run Code Online (Sandbox Code Playgroud)

给我错误.我关心的重载函数有这些原型:

//for matrix addition
Matrix operator+(Matrix& m)

//for stream insertion operator
ostream& operator<<(ostream& out, Matrix & m)
Run Code Online (Sandbox Code Playgroud)

你们可以在我出错的地方帮助我吗?如果需要,我可以发布实际代码.

c++ reference class operator-overloading

0
推荐指数
1
解决办法
38
查看次数

C++ lambda:良好的参考与糟糕的参考

我正在观看CppCon 2015视频:为什么按价值捕捉是好的,而参考则是坏的.

在此输入图像描述

Arthur解释说,但是我没理解...... Arthur说一个错误的引用是指一个局部变量然后退出,但退出堆栈后应该清理并且局部变量消失了,那么问题是什么?

c++ lambda reference pass-by-reference

0
推荐指数
2
解决办法
185
查看次数

Java ArrayList问题

我试图允许"Admin"类创建多个数组.但是,每次运行此循环时,它似乎都会删除先前创建的数组.

   do { 
                System.out.println("\nWhat do you want "
                 + "the name of your line to be?: ");

              String lineName= keyboard1.nextLine();


   System.out.println("\n\nCongratulations! \n"+ "Your "+ lineName +
          " queue has been created! \n");


       //Create an array that will hold "User" information.
        ArrayList<User>queue=new ArrayList<>();


        //Create an array of arrays to allow "User" to see all "lines" available to them.
        ArrayList<String>totalLines=new ArrayList<>();
            `//Add the array name to the array of arrays.     
               `totalLines.add(lineName);
        //Show Admin all of their lines.
         System.out.println("Here is a list of …
Run Code Online (Sandbox Code Playgroud)

java arrays variables reference arraylist

0
推荐指数
1
解决办法
52
查看次数

使用**更改地址的值

我已经读过它意味着指向指针的指针.但在下面的代码中,我能够更改地址的值.

int main() {

    int x = 23;           // initializing variable X = 23
    int *myVar = &x;      // Creating a pointer to the address of X
    *myVar = 566;         // My attempt at changing the value of X address
    cout << x << endl;    // Printing out X with new value

}
Run Code Online (Sandbox Code Playgroud)

它解决了.这怎么可能?**是指地址的价值吗?

c++ pointers reference

0
推荐指数
1
解决办法
1498
查看次数

.aspx和.cs之间的参考

如何在.aspx站点上的按钮事件和函数类.cs之间构建引用?

这是.aspx页面:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent1" Runat="Server">
    <form id="form1" runat="server">
<div class="contentText">

   <div class="row">
   <label for="name">Name:</label>
       <input type="text" id="name" name=""><br><br>
   </div>

   <div class="row">
       <label for="address">Address:</label>
       <input type="text" id="address" name=""><br><br>
   </div>

   <div class="row">
       <label for="phone">Phone:</label>
       <input type="tel" id="phone" name=""><br><br>
   </div>

   <div class="row">
       <label for="email">Email:</label>
       <input type="email" id="email" name="">
   </div>
    </div>
    <div>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
        <asp:GridView ID="GridView1" runat="server" >
        </asp:GridView>
    </div>
</form>
</asp:Content>
Run Code Online (Sandbox Code Playgroud)

在这里你可以看到我的班级.cs.

public class Login
{
    protected …
Run Code Online (Sandbox Code Playgroud)

c# asp.net reference

0
推荐指数
1
解决办法
200
查看次数