- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在为一个 C++ 项目工作,但我想知道如何从析构函数中的类/结构调用成员函数。我项目的其余部分进展顺利,所以我只需要知道它就可以完成:)
~Drink()
{
cout << "hi";
cout << "I want to know how to summon a member function from a destructor.";
}
int Drink::dailyReport()
{
cout << "This is the member function I want to call from the destructor.";
cout << "How would I call this function from the destructor?"
}
正确的语法和所有将不胜感激!如何从析构函数调用成员函数的示例会很可爱!
最佳答案
这里的问题是您没有为析构函数添加前缀 Drink::
由于析构函数不知道它应该与哪个类相关联(假设它是在类声明之外定义的),它甚至不知道它有一个成员函数要调用。
尝试将您的代码重写为:
Drink::~Drink() // this is where your problem is
{
cout << "hi";
cout << "I want to know how to summon a member function from a destructor.";
dailyReport(); // call the function like this
}
int Drink::dailyReport()
{
cout << "This is the member function I want to call from the destructor.";
cout << "How would I call this function from the destructor?"
}
关于c++ - 如何从析构函数中调用成员函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36256319/
我开始考虑在我 future 的项目或重构中实现控制反转容器,我想知道在正确设计依赖项时哪些原则(除了 GoF 模式)可能需要牢记在心。假设我需要构建一个简单的控制台应用程序,如果它可以访问互联网,它
假设我有一个 RxC contingency table 。这意味着有 R 行和 C 列。我想要一个维度为 RC × (R + C − 2) 的矩阵 X,其中包含行的 R − 1 “主效应”以及列的
我正在尝试使用 DKMS 为正在运行的内核 (4.4) 构 build 备树覆盖。我天真的 Makefile 如下: PWD := $(shell pwd) dtbo-y += my-awsome-o
我有一个 sencha touch 项目。我是用 phonegap 2.9 构建的,并且可以正常工作 device.uuid 返回到设备 ID。当我尝试使用 3.1 device.uuid 构建时抛出
我在安装了 Xcode 4.5.1 的 Mt Lion 上运行。 默认情况下,当我构建并部署到 iOS 5.1 设备时,显示会在我旋转设备时旋转,但当我部署到 iOS 6 模拟器或运行 iOS 的 i
我正在尝试使用 Google Analytics Reporting API v4 构建多折线图。 一张图表,其中我按每天的 session 计数为每个设备(台式机/平板电脑/移动设备)设置了一条线。
我一生都无法使用 xcode 组织者“自动设备配置”中的“团队配置配置文件”在 xcode 4.0.1 中将我的应用程序构建到我的 iPad 上。 该应用程序完美地构建到模拟器,但当我构建到 iPad
我是一名优秀的程序员,十分优秀!