我对shared_ptr感到困惑.
说,我有课:
class foo {
int _f;
};
typedef std::shared_ptr<foo> fooptr;
class bar {
int _b;
};
typedef std::shared_ptr<bar> barptr;
class foobar : public foo, public bar {
int _fb;
};
int main () {
foobar *fb1 = new foobar();
foobar *fb2 = new foobar();
fooptr f((foo *)fb1);
barptr b((bar *)fb2);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
因为b.get()!= fb2,所以它应该在程序退出时崩溃?还是安全的?
我有一个关于RegOpenKeyEx的问题,代码:
#include <tchar.h>
#include <stdio.h>
#include <windows.h>
#pragma comment (lib, "Advapi32.lib")
int main () {
TCHAR *keyName = _T("SOFTWARE\\foobar2000\\capabilities");
HKEY key = NULL;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, KEY_ALL_ACCESS, &key) != ERROR_SUCCESS) {
printf("open key failed!\n");
return -1;
} else {
printf("open key success!\n");
}
TCHAR *value = _T("123");
if (RegSetValueEx(key, _T("xxx"), 0, REG_SZ,
(const BYTE *)value, sizeof(TCHAR) * (_tcslen(value) + 1)) != ERROR_SUCCESS) {
printf("set value failed!\n");
}
RegCloseKey(key);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
保存代码,例如reg.cpp和命令模式:
cl reg.cpp
我得到了reg.exe,运行它:
d:\ TMP> REG.EXE
开放成功! …