小编bip*_*pll的帖子

当泛型类型绑定到 Any 时,kotlin 重载解析歧义

考虑这段代码

fun main() {
    class A<T> {
        fun m(t: T): Unit {
            print("T")
        }
        fun m(t: List<T>): Unit {
            print("List<T>")
        }
    }
    
    val a: A<Any> = A()
    val l: List<Any> = listOf()
    a.m(l)
}
Run Code Online (Sandbox Code Playgroud)

a.m(l)调用似乎不明确,并出现以下错误:

重载解析歧义: public final fun m(t: Any): main.A 中定义的单位 public final fun m(t: List<Any>): main.A 中定义的单位

我的直觉告诉我,m(t: List<T>)重载应该更具体,但我的直觉已经错误了一次,当时我在 Java 中遇到过类似的情况

我可以这样称呼“错误”的重载:

a.m(l as Any)
Run Code Online (Sandbox Code Playgroud)

但是我怎样才能明确地调用所需的m(t: List<T>)重载呢?铸造a.m(l as List<Any>)不起作用。

generics overload-resolution kotlin

5
推荐指数
1
解决办法
858
查看次数

如何在 Powershell 中使用逻辑与 (&amp;&amp;)?

在终端中,我曾经使用“&&”运算符同时运行两个命令。例如,如果我想编译并运行 C 源代码,我只需要编写: gcc code.c && ./a.out。但不幸的是它在 Powershell 中不起作用。我怎样才能做到这一点?很抱歉我找不到任何更简单的方法来做到这一点。因此,我不得不将其发布在这里!蒂亚!

windows terminal powershell

4
推荐指数
1
解决办法
6928
查看次数

功能中的注释参数

我本来打算通过实施seekpos流缓冲的GNU在线文档源.我无法理解为什么__mode在行中注释ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out以及它为什么不抛出错误.

  virtual pos_type 
  seekpos(pos_type, ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
   {
      return pos_type(off_type(-1));
   }
Run Code Online (Sandbox Code Playgroud)

我可以理解评论的用法,如果它是以下格式:

void foo( pos_type, int /*blah*/ ){
...
}
Run Code Online (Sandbox Code Playgroud)

但是,在前一种情况下,还有意图分配一些东西__mode,因此我很惊讶没有在那里得到任何错误.

这是允许的吗?如果是,那为什么呢?

c++

4
推荐指数
1
解决办法
128
查看次数

Web Audio api:如何从一开始就不断增加声音的音量

为了不让听众感到窒息,我想播放一个波形,但音量不应该从一开始就以 100% 的比例播放,例如,它应该在 2 秒的持续时间内从 0% 到 100%。

我考虑了 setTimeout 并增加了时间增益,但我不知道是否还有其他更好的方法

    var source = aCtx.createBufferSource();
    source.buffer = buf;
    var gainNode = aCtx.createGain();
    gainNode.gain.value = 0
    source.connect(gainNode);
    gainNode.connect(aCtx.destination);
    source.start(0);

setTimeout(function() {
     gainNode.gain.value = 0.5
}, 1000)

setTimeout(function() {
     gainNode.gain.value = 1
}, 2000)
Run Code Online (Sandbox Code Playgroud)

javascript web-audio-api

2
推荐指数
1
解决办法
1405
查看次数

Struct的指针以及如何访问元素

我想为struct的巫婆构造函数和析构函数创建一个小例子,但我的问题是我不能"打印"Zahlen [0]而我不知道为什么?

感谢任何帮助.

也许我必须用指针参数打印它?

#include <iostream>
using namespace std;

struct IntList{
    int *memory;
    int size;

    // Konstruktur
    IntList(unsigned initialSize = 0) {
        memory = new int[initialSize];// Speicher reservieren (0 erlaubt)
        size = initialSize;
    }

    //Destruktor
    ~IntList() {
        delete []memory; // Speicher freigeben
    }

    // Access Elemnts
    int &operator[](unsigned index) {
        if (index>=size) {throw std::out_of_range("out of bounds");}
        return memory[index];
    }
};



int main()
{
    IntList *Numbers = new IntList(10);
    Numbers[0] = 1;
    cout << Numbers[0] << endl;
    delete Numbers;

    return 0; …
Run Code Online (Sandbox Code Playgroud)

c++ c++11 c++14

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

为什么我在使用 sum(n1,n2) 时出现这个错误,但在使用 n1+n2 时却没有出现错误?

def makes_twenty(n1,n2):
    return sum(n1,n2)
makes_twenty(20,10)
Run Code Online (Sandbox Code Playgroud)
TypeError
Traceback (most recent call last)
<ipython-input-36-65c96a963589> in <module>
      1 # Check
----> 2 makes_twenty(20,10)

<ipython-input-35-9571a81855ca> in makes_twenty(n1, n2)
      1 def makes_twenty(n1,n2):
----> 2     return sum(n1,n2)

TypeError: 'int' object is not iterable
Run Code Online (Sandbox Code Playgroud)

python python-3.x

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