假设我们有A级:
class A
{
double x;
double y;
A(double, double);
function <double(void)> F;
};
Run Code Online (Sandbox Code Playgroud)
以下构造函数:
A::A(double a, double b)
{
x = a;
y = b;
F = [this]() { return x + y; };
}
Run Code Online (Sandbox Code Playgroud)
为什么上述构造的工作,而下面的构造会导致编译错误:member A::x is not a variable?(相同的错误y.)
A::A(double a, double b)
{
x = a;
y = b;
F = [x,y]() { return x + y; };
}
Run Code Online (Sandbox Code Playgroud)
我似乎只能捕捉this而不是集体成员.这是为什么?
我试图理解Java中的参考比较.我们假设我们有以下主要代码:
public static void main (String args[]) {
String str1 = "Love!";
String str2 = "Love!";
String str3 = new String("Love!");
String str4 = new String("Love!");
String str5 = "Lov"+ "e!";
String str6 = "Lo" + "ve!";
String s = "e!";
String str7 = "Lov"+ s;
String str8 = "Lo" + "ve!";
String str9 = str1;
}
Run Code Online (Sandbox Code Playgroud)
我理解这一点str1 == str2 == str5 == str6 == str8 == str9,所有这些都是对公共池的引用.(价值"爱!").
s也是对公共池的引用,但它引用值"e!"
我也明白str1 != s.
我知道str3, …
我正在尝试理解Java super()构造函数.我们来看看下面的课程:
class Point {
private int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public Point() {
this(0, 0);
}
}
Run Code Online (Sandbox Code Playgroud)
这个类将编译.如果我们创建一个新Point对象Point a = new Point();,那么将调用没有参数的构造函数:Point().
如果我错了,请纠正我,在做之前this(0,0),Class将调用构造函数,然后Point(0,0)才会调用它.如果这是真的,那么说super()默认情况下是否正确?
现在让我们看一下相同的代码并进行一些小改动:
class Point {
private int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public Point() {
super(); // this is the change. …Run Code Online (Sandbox Code Playgroud) 我有两个数据框,它们具有完全相同的列和相同的行数.
我想创建一个新的数据框,它包含两个数据框,但交替绑定行.它必须从第一个数据帧获取一行,从第二个数据帧获取一行,直到构建整个新数据帧.
我试着rbind()没用好运.我需要一个不包括安装新R包的解决方案.
图片用于演示:
编辑:我的行数是动态的,可能非常大.此外,我需要一个不依赖于列名的解决方案,因为结构也是动态的.我知道这两个数据帧每次都有相同的结构.