- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在这里,我在 main()
中调用类 a
的构造函数,但没有创建该类的对象,看起来析构函数在调用后立即被调用。这里到底发生了什么?据我了解,这是因为我没有创建具有内存的对象吗? dtor 是如何在这里被调用的?它是如何实现的?请分享您对此的看法。
#include<iostream>
using namespace std;
class a{
public:
a(){
cout<<"\nctor";
}
~a(){
cout<<"\ndtor";
}
};
int main(){
a(); //why the dtor is getting called before the scope ends?
cout<<"\nctor_called\n";
}
程序的o/p:
ctor
dtor
ctor_called
最佳答案
您没有调用构造函数(您不能直接调用)。您正在构建一个立即销毁的临时对象。
尝试
a anA;
关于c++ - 当我从 main 调用 ctor 时,为什么在范围结束之前调用 dtor? (实验性的),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22793900/
我尝试在 gcc 6.0 中实际使用新的 c++1z 功能。 如果我尝试这个小例子: #include #include namespace fs = std::experimental::fil
我有兴趣为一个副项目构建一个新风格的 IDE。主要是为了取消类固醇IDE上的普通记事本。我正在为已经尝试过的或者你已经看到(或没有看到)看起来很酷并且在 IDE 中有用的东西寻找一些灵感。我可以解决的
使用实验性 CSS 属性如 border-radius、text-shadow、box-shadow 和 gradient 在今天的布局中?像 rgba() 这样的值呢? 当我查看网络画廊时,这些 C
我想制作一个 chrome 扩展,作为浏览器窗口的面纱。用户访问网站的次数越多,他们的历史记录就越多。我看过一些 chrome 扩展程序,但它们似乎都链接到一个图标,每次你访问一个新站点时,弹出窗口都
我想在 C++17 中删除包含子文件夹和文件的文件夹。我正在使用 experimental/filesystem namespace filesys = std::experimental::file
我正在尝试设置我的应用程序以使用 Airflow 的实验性 API。我正在使用 apache-airflow==1.10.2 . 使用开箱即用的配置(未启用身份验证),我能够使用 POST /api/
我在 these examples 之后使用 gradle 构建了一些测试 c 和 c++ 程序 在 this answer 的帮助下,我还能够设置具有实验功能的 android studio 来构建
我只是尝试实现一个充当代理的 python 应用程序(用于端口 22)代码如下: import socket import select import code inputSock = socket.
是否存在适用于 Ruby 的(实验性)类浏览器? 我说的是类似于大多数 Smalltalk 实现的类浏览器/编辑器组合(即专注于 [运行时] 类/对象而不是 .rb 文件) P.S.:看起来 pry
引用: Using the new code snippets feature in google chrome 我正在 google chrome 中使用代码片段,所以说我有一个片段文件。check
我有一个 Android 项目,我们使用实验性 Gradle 插件已有一段时间了。随着 Android Studio 3 的发布和向 Gradle 4 的迁移,我有几个问题 在几个月内没有人添加新的实
我尝试实现一个 make_array 的版本,它不完全相同,但非常类似于: http://en.cppreference.com/w/cpp/experimental/make_array 我发现这段
当我更新 ddev 版本 1.19.0 时,drush 命令不起作用。 $ ddev drush OCI runtime exec failed: exec failed: container_lin
我想使用 USB 实验性 api 开发一个 chrome 扩展。我从来没有设法找到我的 USB 设备已连接。这个扩展的起点是这段代码: knob example我更改了 vid 和 pid 以匹配我的
我们如何使用 C API 在 Tensorflow Lite 中创建张量?然后我们如何将它们与解释器一起使用? 我知道 Tensorflow Lite 有 C++ API 的文档,而常规的 Tenso
我玩了一下 experimental device lambdas在 CUDA 7.5 中引入并在此 blog post by Mark Harris 中提升. 对于下面的示例,我删除了很多不需要显示
我正在关注这篇文章 @ https://firebase.googleblog.com/2018/01/streamline-typescript-development-cloud-function
我的问题是我找不到一些合适的文档/指南来遵循以正确设置我的环境。 基本上我使用的是 Android Studio 1.3.2(截至 2015 年 9 月 22 日的最新稳定版)和 Gradle 实验版
我有一个使用 opencv android sdk 的项目,为了加快速度,我决定用 C++ 实现一些功能。 无论如何,我正在使用 gradle 实验性插件 0.4.0 以及何时为 arm64-v8a
我正在尝试在 Android Studio 中使用 NDK 运行一些 native 代码。我已按照显示的步骤进行操作 HERE使用实验性的 Gradle,但显然并不是一帆风顺。我收到此错误:必须将 a
我是一名优秀的程序员,十分优秀!