例如,我可以输入一个表情符号字符代码,例如:
NSString* str = @"";
NSLog(@"%@", str);
Run Code Online (Sandbox Code Playgroud)
将在控制台中看到微笑表情符号。
也许代码编辑器和编译器会在 UTF-8 中交换文字。
现在我在一个完整的 unicode 中工作,我的意思是每个字符 32 位,环境,我有表情符号的 unicode,我想将 32 位 unicode 转换为 NSString 例如:
int charcode = 0x0001F60A;
NSLog(@"%??", charcode);
Run Code Online (Sandbox Code Playgroud)
问题是我应该把什么放在“??” 位置然后我可以将字符代码格式化为表情符号字符串?
顺便说一句,charcode 是一个在编译时无法确定的变量。
我不想将 32 位 int 压缩为 UTF-8 字节,除非这是唯一的方法。
考虑我有这样的代码:
#include <initializer_list>
class my_class
{
public:
my_class() {}
void operator = (const std::initializer_list<int>&) {} // OK
template<typename ValueType> void operator = (const ValueType&) {} // Failed
};
int main(int argc, char* argv[])
{
my_class instance;
instance = {1, 2};
return 0;
}
Run Code Online (Sandbox Code Playgroud)
第一个复制赋值运算符可以编译为OK instance = {1, 2}.但是,模板版本将失败并出现此类错误:
code.cpp:15:14: error: no viable overloaded '='
instance = {1, 2};
~~~~~~~~ ^ ~~~~~~
code.cpp:3:7: note: candidate function (the implicit copy assignment operator) not viable: cannot convert initializer list argument to 'const …Run Code Online (Sandbox Code Playgroud) 我正在制作一个类装饰器,我想限制这个装饰器只能应用于某些类,所以我这样做了:
@decorator()
class A {
foo:string;
}
@decorator()
class B extends A {
}
@decorator()
class C {}
function decorator () {
// This makes decorators work on class A and B except class C
return function<T extends typeof A> (target:T) {}
// This makes decorators become error on all the classes
// return function<T extends A> (target:T) {}
}
Run Code Online (Sandbox Code Playgroud)
如果我将其更改function<T extends typeof A> (target:T) {}为,function<T extends A> (target:T) {}那么所有装饰器都会出错。
我不确定为什么我必须使用extends typeof A而不是extends …
在operator new与operator new[]具有相同的函数原型:void * (size_t size).当我要超负荷时,我应该注意什么?
如果我只是超载,那可以operator new吗?
超载operator delete和operator delete[]?之间有什么区别?
我知道这段代码看起来很奇怪,但我想知道是否有任何方法可以使它编译.
template<typename T>
class A
{
public:
enum
{
template_class_id = T::class_id
};
};
class B : public A<B>
{
public:
enum
{
class_id = 0x1234
};
};
Run Code Online (Sandbox Code Playgroud)
我得到这样的错误:
clang++ test.cpp
test.cpp:7:32: error: no member named 'class_id' in 'B'
template_class_id = T::class_id
~~~^
test.cpp:11:18: note: in instantiation of template class 'A<B>' requested here
class B : public A<B>
^
1 error generated.
Run Code Online (Sandbox Code Playgroud)