考虑以下Win32 API结构:
typedef struct _SECURITY_ATTRIBUTES {
DWORD nLength;
LPVOID lpSecurityDescriptor;
BOOL bInheritHandle;
} SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES;
Run Code Online (Sandbox Code Playgroud)
将此对象移植到C#时,我应该遵循此处使用的名称命名约定,如下所示:
public struct _SECURITY_ATTRIBUTES
{
public int nLength;
public unsafe byte* lpSecurityDescriptor;
public int bInheritHandle;
}
Run Code Online (Sandbox Code Playgroud)
或者我可以全力以赴,并以C#样式编写我的结构,如下所示:
public struct SecurityAttributes
{
private int length;
private unsafe byte* securityDescriptor;
private int bInheritHandle;
public Int32 Length
{
get { return this.length; }
set { this.length = value; }
}
public Byte* SecurityDescriptor
{
get { return this.seurityDescriptor; }
set { this.securityDescriptor = value; }
}
public …Run Code Online (Sandbox Code Playgroud) 我使用C++语言环境方面的工作越多,我理解的就越多 - 它们就被打破了.
std::time_get- 与std::time_put(因为它在C strftime/strptime中)不对称,并且不允许使用AM/PM标记轻松解析时间.ru_RU.UTF-8).std::ctype 假设可以在每个字符的基础上完成上/下更新(情况转换可能会改变字符数并且它取决于上下文),这是非常简单的.std::collate - 不支持校对强度(区分大小写或不区分大小写).以及更多...
谢谢.
编辑:澄清链接无法访问:
std::numpunct将千位分隔符定义为char.因此,当U + 2002中的分隔符 - 不同类型的空间时,它不能作为单个字符在UTF-8中再现,而是作为多字节序列.
在C API中,struct lconv将千位分隔符定义为字符串,并且不会遇到此问题.因此,当您尝试使用UTF-8语言环境在ASCII之外的分隔符格式化数字时,会生成无效的UTF-8.
要重现此错误,请使用imbued ru_RU.UTF-8locale 将1234写入std:ostream
EDIT2:我必须承认POSIX C本地化API工作得更顺畅:
std::time_put::put)然而,它仍然是完美的.
编辑3:根据有关C++ 0x的最新说明,我可以看到std::time_get::get- 与...类似strptime和相反std::time_put::put.
我发现滚动条(禁用或启用)将显示在div的两侧,尽管元素是否已达到其最大长度.只需将overflow:value; 它会自动显示它们.如何使滚动条仅在元素达到最大高度时显示?
我已经看到了许多循环和增量.而不是做i ++他们做i + = 1.这是为什么?
我必须将一些枚举打包到byte array(char*)并通过网络发送.可以将枚举的默认类型设置为unsigned char吗?(我现在可以转换或使用& 0xff提取第一个字节/ char,但这需要额外的操作,所以有没有办法在enum的定义中解决这个问题?)
我来自Java并且正在学习C++.我正在使用Stroustrup的Progamming原则和使用C++的实践.我现在正在使用矢量.在页117,他说,访问向量的不存在元素将导致运行时错误(在Java中相同,索引超出范围).我正在使用MinGW编译器,当我编译并运行此代码时:
#include <iostream>
#include <cstdio>
#include <vector>
int main()
{
std::vector<int> v(6);
v[8] = 10;
std::cout << v[8];
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它给了我作为输出10.更有趣的是,如果我不修改不存在的向量元素(我只打印它期望运行时错误或至少是默认值)它会打印一些大整数.那么...... Stroustrup是错误的,还是GCC有一些编译C++的奇怪方法?
我使用g ++来编译带有压缩字段的代码.但是,我尝试返回对打包字段的引用时收到错误.
例:
struct __attribute__((packed)) Foo {
int* ptr;
uint16_t foo;
int*& getPtr(){
return ptr;
}
};
Run Code Online (Sandbox Code Playgroud)
产量错误:
test.cpp:22:14: error: cannot bind packed field ‘((Foo*)this)->Foo::ptr’ to ‘int*&’
return ptr;
Run Code Online (Sandbox Code Playgroud)
为什么我不能返回对打包字段的引用?
当用户在键入时暂停(而不是在每次按键后)时,我想触发一个ajax动作.所以我做了这样的事情:
当用户在空闲3秒后停止输入时,将执行完成功能...(它是 - 但为什么3次长短语 - 我希望它只运行一次,因为我在每次keydown后清除超时).问题是什么 ?
var timer;
var interval = 3000;
$('#inp').keyup(function() {
timer = setTimeout(done, interval);
});
$('#inp').keydown(function() {
clearTimeout(timer)
});
function done() {
console.log('ajax');
}
Run Code Online (Sandbox Code Playgroud)
关于jsfiddle的工作示例:http: //jsfiddle.net/vtwVH/
我通常会看到const 用于表示const成员函数的说明符.但是当使用volatile关键字时它意味着什么?
void f() volatile {}
Run Code Online (Sandbox Code Playgroud)
这对我来说很好,但我不明白这是什么.我在搜索中找不到任何关于此的信息,所以任何帮助都表示赞赏.
更新:为了说清楚,我知道它volatile是为了什么.我只是不知道在这种情况下它意味着什么.
以下代码在Clang中编译,但在GCC中不编译.当我operator()使用左值调用时,它可以工作,但不能使用右值.为什么?
struct S
{
bool operator()() const & { return true; }
bool operator()() const && { return true; }
};
int main()
{
S s;
s(); // works
S()(); // fails (error: call of '(S) ()' is ambiguous)
}
Run Code Online (Sandbox Code Playgroud)
我正在GCC 4.8上编译这段代码.