据我所知,与公有继承时,通常不是安全时,由于delete
荷兰国际集团一个基类指针编译器只生成的代码来调用基类的析构函数,并且派生类的一个不叫.
但是对于私有继承,客户端不能将派生类指针强制转换为基类指针(因为私有继承不建模is-a关系),所以delete
总是在派生类的指针上使用,编译器应该能够看到那里也是一个基类并调用它的析构函数.
我做了这个测试:
#include <iostream>
struct BaseVirtual
{
virtual ~BaseVirtual()
{
std::cout << "BaseVirtual's dtor" << '\n';
}
};
struct BaseNonVirtual
{
~BaseNonVirtual()
{
std::cout << "BaseNonVirtual's dtor" << '\n';
}
};
struct DerivedPrivVirtual: private BaseVirtual
{
static void f()
{
BaseVirtual * p = new DerivedPrivVirtual;
delete p;
}
~DerivedPrivVirtual()
{
std::cout << "DerivedPrivVirtual's dtor" << '\n';
}
};
struct DerivedPrivNonVirtual: private BaseNonVirtual
{
static void f()
{
BaseNonVirtual * p …
Run Code Online (Sandbox Code Playgroud) 我刚刚介绍了"程序切片"这个术语.人们想要这样的功能是完全合理的,但是它存在于任何地方吗?
这个词现在已经20岁了,我看到有很多出版物,研究论文等等.但实际的工具在哪里?人们是否真的将这个概念付诸实践,或者只是在学术上研究它?
什么在那里,以及什么语言?
编辑:我想我正在寻找什么,我作为一个接受的答案奖励,是一些出版物/组织/等的参考,特别是面向程序切片和维护工具/技术等的列表.
code-analysis static-analysis dynamic-analysis analysis utility
如何在Windows上读取快捷方式文件的目标.尝试使用boost :: read_symlink抛出异常,说"文件或目录不是重新分析点"消息.
int main(int argc, _TCHAR* argv[])
{
try {
boost::filesystem::path target = boost::filesystem::read_symlink("c:\\tmp\\blobstore_2.lnk");
cout<<target.string();
} catch(const boost::filesystem::filesystem_error& ex)
{
cout<<"in catch"<<ex.what(); // prints "the file or directory is not a reparse point"
}
std::ifstream smbConfStream("c:\\tmp\\sym_file_2.lnk");
string ss((std::istreambuf_iterator<char>(smbConfStream)),
std::istreambuf_iterator<char>());
cout <<endl<<" ss: "<<ss; // From the output of the "ss" it looks like the information of the target is present inside ss along with other binary data. How to cleanly get the target out.
int i;
cin>>i;
return 0; …
Run Code Online (Sandbox Code Playgroud) 在一个解决方案中,我有两个VC++项目.项目A具有链接器输入,这些输入是由项目B编译的.obj文件.
Visual Studio(2008)总是告诉我项目A"已经过时",并且每次我想运行/ debug/build/etc时都会提示我询问是否要重建它.甚至在构建整个解决方案之后立即:我做了一个成功的完整构建,然后再次单击Build,它想要重新链接Project A.
我怎样才能防止这种情况发生?任何人都明白这里发生了什么?
我想在下面做这样的事情:
int main() {
int a[10];
int *d = generateArrayOfSize(10) // This generates an array of size 10 on the heap
a = d;
print(a); // Prints the first 10 elements of array.
}
Run Code Online (Sandbox Code Playgroud)
但是上面的代码给出了编译错误(将'int*'赋值给'int [10]'的类型不兼容).我可以做些什么来使上面的代码工作?
有没有办法将搜索模式保存到寄存器,然后用一些快速命令召唤它?
我正在考虑vim使用带有q和@的命名寄存器的方式,以及带有m和'的命名标记.
如何在Fossil SCM中重命名维基页面?
在我的特定情况下,我想重命名我的项目(在管理员,配置,项目名称中),但如果我这样做,那么当我在主菜单中单击主页时,不显示任何内容,因为还没有一个名称的Wiki页面匹配我的新项目名称.我想重命名我的项目,并重命名我的(唯一)维基页面以匹配.
似乎在JavaScript中可以做到:
function extendPromise(promise) {
return promise.then(new Promise(() => {}));
}
Run Code Online (Sandbox Code Playgroud)
但是如果我添加类型,比如
function extendTypeScriptPromise(promise: Promise<void>) {
return promise.then(new Promise<void>(() => {}));
}
Run Code Online (Sandbox Code Playgroud)
然后TypeScript编译器说:
error TS2345: Argument of type 'Promise<void>' is not assignable to parameter of type '((value: void) => void | PromiseLike<void>) | null | undefined'.
Type 'Promise<void>' is not assignable to type '(value: void) => void | PromiseLike<void>'.
Type 'Promise<void>' provides no match for the signature '(value: void): void | PromiseLike<void>'.
Run Code Online (Sandbox Code Playgroud)
为什么不Promise<void>
考虑PromiseLike
?
我想我正在使用Enterprise COBOL for z/OS.
有什么技术可以模拟标准C库的sleep()函数的功能?
c++ ×4
analysis ×1
boost ×1
cobol ×1
destructor ×1
dia ×1
fossil ×1
inheritance ×1
mainframe ×1
tool-uml ×1
typescript ×1
uml ×1
utility ×1
vim ×1
visual-c++ ×1
winapi ×1
windows ×1
zos ×1