<p>I am trying this:</p>
<pre><code>C.notify_notification_show(n, &new(C.GError))
</code></pre>
<p>It complains that I <code>cannot take the address of new(_Ctype_struct__GError)</code>.</p>
<p>How should I do it without assigning it in a variable?</p>
<hr/>**评论:**<br/><br/>chrj: <pre><p><code>new</code> already returns a pointer. Try just removing the <code>&</code>.</p></pre>dominikh: <pre><p>He needs a pointer to a pointer. At the same time, using any form of <code>new</code> in that function call defeats the point of the second argument, which is basically the equivalent to an <code>error</code> return in Go.</p></pre>chrj: <pre><p>You're right. I didn't notice the double pointer. I haven't had my morning coffee yet :)</p></pre>decapolar: <pre><p>Well I did this and it worked:</p>
<pre><code>new(*C.GError)
</code></pre></pre>epiris: <pre><p>I don't know what library you are using but they can not deref the value with that, i.e. <code>**v</code> would panic. I really don't think you should do this, I would consider any code that did low quality: <code>&[]*int{new(int)}[0]</code></p></pre>mixiegen: <pre><pre><code>var err = new(C.GError)
C.notify_notification_show(n, &err)
</code></pre>
<p>Not any value can be taken address in Go: <a href="https://go101.org/article/summaries.html#not-addressable" rel="nofollow">https://go101.org/article/summaries.html#not-addressable</a></p>
<p><code>new</code> is a function, function return results can't be taken addresses.</p></pre>decapolar: <pre><p>Need a one liner.</p></pre>tv64738: <pre><p>Why?</p></pre>feddasch: <pre><p>Add a semicolon after the variable</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传