【发布时间】:2022-08-14 19:54:03
【问题描述】:
在 Objc 源代码中,我找到了以下代码。这段代码是什么意思,如何理解?
objc/项目标头/DenseMapExtras.h 行:38
template <typename Type>
class ExplicitInit {
alignas(Type) uint8_t _storage[sizeof(Type)];
public:
template <typename... Ts>
void init(Ts &&... Args) {
new (_storage) Type(std::forward<Ts>(Args)...);
}
Type &get() {
return *reinterpret_cast<Type *>(_storage);
}
};
下面是我的测试代码:
class MyC{
public:
long l1;
long l2;
MyC(long _l1, long _l2){
l1 = _l1;
l2 = _l2;
}
};
int main(){
MyExplicitInit<MyC> e1 {};
e1.init();
return 0;
}
-
这段代码是什么意思,如何理解?-- C++ 是最难学的语言之一。你不能通过挑选你在某处找到的代码并试图理解它来学习它。你对转发参数了解多少?安置新的?结盟?如果不首先了解 C++ 超出初学者阶段,您将不会得到答案(无论如何,最好的 C++ 书籍可以回答)。
-
更简单。这里应该如何填写参数?
-
@Crazs 请参阅good c++ book。
标签: c++ ios objective-c