小编Hin*_*sum的帖子

C++ 11 unique_ptr和shared_ptr是否能够转换为彼此的类型?

难道C++ 11标准库提供任何实用程序从一个转换std::shared_ptrstd::unique_ptr,或反之亦然?这是安全的操作吗?

c++ shared-ptr unique-ptr c++11

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

为什么编译器将"char"与"int"匹配而不是"short"?

我有一个小程序:

#include<iostream>
using namespace std;

void f(int)   { cout << "int\n";   }
void f(short) { cout << "short\n"; }

int main(void){
    char c = 0;
    f(c);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

它打印int.我觉得,如果这是因为"整体推广",为什么不short首选?

我也知道整数提升发生在表达式中(如A = B).但是我没有接到电话中的表情f(),吗?

如果这是重载解决规则有关,为什么传递char到F将导致到编译器宁愿intshort

如果我删除f(int),那么f(c)会打电话f(short)!

总而言之,我的问题是,它是与"整数提升"还是仅仅是"超载解决规则"有关?为什么?

c++ overloading type-conversion

69
推荐指数
2
解决办法
3266
查看次数

如何在我的ubuntu docker镜像中安装"ifconfig"命令?

我刚刚安装了ubuntu docker镜像,当我执行"ifconfig"它说没有这样的命令时,我尝试了apt-get install,因为没有名为"ifconfig"的软件包(我可以安装其他一些图像).

那怎么做?谢谢.

ubuntu image ifconfig docker

68
推荐指数
2
解决办法
10万
查看次数

docker restart容器失败:"已经在使用中",但是没有更多的docker镜像

我首先得到了我的nginx docker图像:

docker pull nginx
Run Code Online (Sandbox Code Playgroud)

然后我开始了:

docker run -d -p 80:80 --name webserver nginx
Run Code Online (Sandbox Code Playgroud)

然后我停了下来:

docker stop webserver
Run Code Online (Sandbox Code Playgroud)

然后我尝试重新启动它:

$docker run -d -p 80:80 --name webserver nginx
docker: Error response from daemon: Conflict. The container name "/webserver" is already in use by container 036a0bcd196c5b23431dcd9876cac62082063bf62a492145dd8a55141f4dfd74. You have to remove (or rename) that container to be able to reuse that name..
See 'docker run --help'.
Run Code Online (Sandbox Code Playgroud)

嗯,这是一个错误.但实际上现在容器列表中没有任何内容:

docker container list
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
Run Code Online (Sandbox Code Playgroud)

为什么我重启nginx图片失败了?怎么解决?

containers list nginx docker

37
推荐指数
2
解决办法
3万
查看次数

在x86中,"test eax,eax"和"cmp eax,0"之间有什么区别

test eax, eax不是更有效cmp eax, 0?是否有test eax, eax必要在cmp eax, 0不满足要求的地方?

x86 assembly

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

"()"如何将语句转换为C++中的表达式?

我有以下代码:

int main() {
    int i=0;
    int j=({int k=3;++i;})+1; // this line
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

它编译并运行.如果我()从"这一行" 删除,那么它不会编译.

我只是好奇这里应用了什么语法规则.

{}包含2条语句,最后声明表示该代码块的"回归"的价值.那为什么需要额外的()一对来使这个返回值可用?

c++ expression return block

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

为什么Java的List有"List.toArray()",但是数组没有"Array.toList()"?

数组没有"toList"函数,因此我们需要"Arrays.asList"辅助函数来进行转换.

这很奇怪:List有自己的函数转换为数组,但是数组需要一些辅助函数来转换为List.为什么不让数组具有"toList"函数,这个Java设计背后的原因是什么?

非常感谢.

java arrays static casting arraylist

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

为什么powershell(ise)有时打印出我执行的代码?

powershell ise有时打印出我的源代码,如果我有:

function f
{
  $a=2
}
$a
Run Code Online (Sandbox Code Playgroud)

它打印:

C:\Users\vics> function f
{
    $a=2
}
$a
Run Code Online (Sandbox Code Playgroud)

为什么如此受欢迎?

printing powershell

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

google protobuf 编译器不会为服务标签生成类?

我正在尝试使用 protobuf 生成使用 RpcChannel 和 RpcController 的服务。我参考了 google protobuf 的语言指南和:

我有这样的示例原型文件:

语法 = "proto2";

message SearchRequest
{
    required string Request = 1;
}

message SearchResponse
{
    required string Response = 2;
}

service SearchService {
    rpc Search (SearchRequest) returns (SearchResponse);
}
Run Code Online (Sandbox Code Playgroud)

然后我编译它:

protoc --cpp_out=./ examples.proto
Run Code Online (Sandbox Code Playgroud)

我有 .h 和 .cc 文件。但是当我搜索生成的代码时,我只找到了“Request”和“Response”的类,而没有找到“SearchService”的类:

examples.pb.h:class SearchRequest;
examples.pb.h:class SearchResponse;
examples.pb.h:class SearchRequest : public ::google::protobuf::Message {
examples.pb.h:  // @@protoc_insertion_point(class_scope:SearchRequest)
examples.pb.h:class SearchResponse : public ::google::protobuf::Message {
examples.pb.h:  // @@protoc_insertion_point(class_scope:SearchResponse)
Run Code Online (Sandbox Code Playgroud)

语言指南网页提供了一个需要使用“SearchService”类的示例(https://developers.google.com/protocol-buffers/docs/proto#services):但在生成的代码中,没有搜索服务. 该指南没有提供 RpcChannel/RpcController 用法的完整示例。

那么如何修复示例以使其正常工作?我搜索了谷歌,但没有找到任何好的 cpp …

c++ rpc controller channel protocol-buffers

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

python:如何更改函数输入参数的值?

我试图修改函数内字符串的值,如下所示:

>>> def appendFlag(target, value):
...     target += value
...     target += " "
...
>>> appendFlag
<function appendFlag at 0x102933398>
>>> appendFlag(m,"ok")
>>> m
''
Run Code Online (Sandbox Code Playgroud)

好吧,似乎“目标”仅在函数内更改,但是如何使新值在函数外可行?谢谢。

python parameters reference function mutable

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