难道C++ 11标准库提供任何实用程序从一个转换std::shared_ptr
到std::unique_ptr
,或反之亦然?这是安全的操作吗?
我有一个小程序:
#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将导致到编译器宁愿int
到short
?
如果我删除f(int)
,那么f(c)
会打电话f(short)
!
总而言之,我的问题是,它是与"整数提升"还是仅仅是"超载解决规则"有关?为什么?
我刚刚安装了ubuntu docker镜像,当我执行"ifconfig"它说没有这样的命令时,我尝试了apt-get install,因为没有名为"ifconfig"的软件包(我可以安装其他一些图像).
那怎么做?谢谢.
我首先得到了我的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图片失败了?怎么解决?
是test eax, eax
不是更有效cmp eax, 0
?是否有test eax, eax
必要在cmp eax, 0
不满足要求的地方?
我有以下代码:
int main() {
int i=0;
int j=({int k=3;++i;})+1; // this line
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它编译并运行.如果我()
从"这一行" 删除,那么它不会编译.
我只是好奇这里应用了什么语法规则.
将{}
包含2条语句,最后声明表示该代码块的"回归"的价值.那为什么需要额外的()
一对来使这个返回值可用?
数组没有"toList"函数,因此我们需要"Arrays.asList"辅助函数来进行转换.
这很奇怪:List有自己的函数转换为数组,但是数组需要一些辅助函数来转换为List.为什么不让数组具有"toList"函数,这个Java设计背后的原因是什么?
非常感谢.
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)
为什么如此受欢迎?
我正在尝试使用 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 …
我试图修改函数内字符串的值,如下所示:
>>> def appendFlag(target, value):
... target += value
... target += " "
...
>>> appendFlag
<function appendFlag at 0x102933398>
>>> appendFlag(m,"ok")
>>> m
''
Run Code Online (Sandbox Code Playgroud)
好吧,似乎“目标”仅在函数内更改,但是如何使新值在函数外可行?谢谢。
c++ ×4
docker ×2
arraylist ×1
arrays ×1
assembly ×1
block ×1
c++11 ×1
casting ×1
channel ×1
containers ×1
controller ×1
expression ×1
function ×1
ifconfig ×1
image ×1
java ×1
list ×1
mutable ×1
nginx ×1
overloading ×1
parameters ×1
powershell ×1
printing ×1
python ×1
reference ×1
return ×1
rpc ×1
shared-ptr ×1
static ×1
ubuntu ×1
unique-ptr ×1
x86 ×1