小编cha*_*anp的帖子

这个构造函数初始值设定项是否会导致悬空引用?

我正在学习Stanley B. Lippman的C++ Primer第4版.在第12.4.1节中,当作者讨论构造函数初始值设定项时,他给出了这个例子:

class ConstRef {
  public:
    ConstRef(int ii);
  private:
    int i;
    const int ci;
    int &ri;
};
// OK: explicitly initialize reference and const members.
ConstRef::ConstRef(int ii): i(ii), ci(i), ri(ii) { }
Run Code Online (Sandbox Code Playgroud)

我怀疑这可能导致悬挂引用ri指向ii,这是暂时的.我对吗?

c++ reference dangling-pointer

15
推荐指数
1
解决办法
942
查看次数

向量子集化性能:名称与索引

如果我有一个v名字的向量:

John       Murray     Lisa       Mike       Joe       Ann 
0.0832090  0.0475580 -0.2797860  0.1086225  0.0104590 -0.0028250 
Run Code Online (Sandbox Code Playgroud)

什么是时间的复杂性v['Joe']v[4]?我想前者会采用O(log n),因为它应该涉及二进制搜索,但我仍然不确定后者是否是O(1).

此外,结果v是否适用于列表/数据框而不是原子向量的情况?

r

6
推荐指数
1
解决办法
214
查看次数

Why this map function does not give traits' simple names

I try to get names of all trait a class extends using getInterfaces which returns an array of trait's names. When I manually access each member of the array, the method getName returns simple names like this

trait A
trait B

class C() extends A, B

val c = C()
val arr = c.getClass.getInterfaces
arr(0).getName // : String = A
arr(1).getName // : String = B
Run Code Online (Sandbox Code Playgroud)

However, when I use map function on arr. The resulting array contains a …

scala traits

3
推荐指数
1
解决办法
91
查看次数

标签 统计

c++ ×1

dangling-pointer ×1

r ×1

reference ×1

scala ×1

traits ×1