- 411
- 268
Последний из способов, наверное, наиболее благоприятный по причине низкой посадки по рантаймуХотелось бы увидеть реализацию подобного на c++
C++:
#include <iostream>
#include <vector>
#include <any>
#include <typeindex>
#include <typeinfo>
struct Man1 {
unsigned long long index = 0LL;
std::string name = "Name";
void doSmth11() {
std::cout << __PRETTY_FUNCTION__ << ' ' <<
this->index << std::endl;
}
void doSmth12() {
std::cout << __PRETTY_FUNCTION__ << ' ' <<
this->name << std::endl;
}
};
struct Man2 {
unsigned long long cost = 2222LL;
std::string group = "Group";
void doSmth21() {
std::cout << __PRETTY_FUNCTION__ << ' ' <<
this->cost << std::endl;
}
void doSmth22() {
std::cout << __PRETTY_FUNCTION__ << ' ' <<
this->group << std::endl;
}
};
int main() {
std::vector<std::any> pool;
pool.push_back(Man1{});
pool.push_back(Man2{});
for (auto&& e : pool) {
if (std::type_index(e.type()) == std::type_index(typeid(Man1))) {
auto restoredMan1 = std::any_cast<Man1>(e);
restoredMan1.doSmth11();
restoredMan1.doSmth12();
} else if (e.type().hash_code() == typeid(Man2).hash_code()) {
auto restoredMan2 = std::any_cast<Man2>(e);
restoredMan2.doSmth21();
restoredMan2.doSmth22();
}
}
}
C++:
#include <iostream>
#include <vector>
struct ManEssential {
virtual void __unused(void) {};
};
struct Man1 : ManEssential {
unsigned long long index = 0LL;
std::string name = "Name";
void doSmth11() {
std::cout << __PRETTY_FUNCTION__ << ' ' <<
this->index << std::endl;
}
void doSmth12() {
std::cout << __PRETTY_FUNCTION__ << ' ' <<
this->name << std::endl;
}
};
struct Man2 : ManEssential {
unsigned long long cost = 2222LL;
std::string group = "Group";
void doSmth21() {
std::cout << __PRETTY_FUNCTION__ << ' ' <<
this->cost << std::endl;
}
void doSmth22() {
std::cout << __PRETTY_FUNCTION__ << ' ' <<
this->group << std::endl;
}
};
int main() {
std::vector<ManEssential*> pool;
pool.push_back(new Man2);
pool.push_back(new Man1);
for (auto&& e : pool) {
if (auto restoredMan1 = dynamic_cast<Man1*>(e)) {
restoredMan1->doSmth11();
restoredMan1->doSmth12();
} else if (auto restoredMan2 = dynamic_cast<Man2*>(e)) {
restoredMan2->doSmth21();
restoredMan2->doSmth22();
}
}
}
C++:
#include <iostream>
#include <vector>
struct Man1 {
unsigned long long index = 0LL;
std::string name = "Name";
void doSmth11() {
std::cout << __PRETTY_FUNCTION__ << ' ' <<
this->index << std::endl;
}
void doSmth12() {
std::cout << __PRETTY_FUNCTION__ << ' ' <<
this->name << std::endl;
}
};
struct Man2 {
unsigned long long cost = 2222LL;
std::string group = "Group";
void doSmth21() {
std::cout << __PRETTY_FUNCTION__ << ' ' <<
this->cost << std::endl;
}
void doSmth22() {
std::cout << __PRETTY_FUNCTION__ << ' ' <<
this->group << std::endl;
}
};
enum class ManSubtype {
kMan1,
kMan2
};
struct ObjectSlicing : public Man1, public Man2 {
const ManSubtype type;
template<typename T>
ObjectSlicing(const T&& man) : type([=] {
if constexpr (std::is_same<T, Man1>()) {
return ManSubtype::kMan1;
} else if constexpr (std::is_same<T, Man2>()) {
return ManSubtype::kMan2;
}
}())
{}
};
int main() {
std::vector<class ObjectSlicing> pool;
pool.push_back(ObjectSlicing(Man1{}));
pool.push_back(ObjectSlicing(Man2{}));
for (auto&& e : pool) {
if (e.type == ManSubtype::kMan1) {
Man1 restoredMan1 = e;
restoredMan1.doSmth11();
restoredMan1.doSmth12();
} else if (e.type == ManSubtype::kMan2) {
Man2 restoredMan2 = e;
restoredMan2.doSmth21();
restoredMan2.doSmth22();
}
}
}
Первоапрельская шутка 2018 года, не воспринимайте всерьезМожно поинтересоваться, откуда информация?
http://modernescpp.com/index.php/no-new-new
samp.dll + 0x66655 =>Каким образом можно поменять расположение киллстата по вертикали?
patch 5 bytes to mov eax,00000010, where 0x10 - Y offset
samp.dll + 0x66668 =>
patch 5 bytes to mov eax,00000020, where 0x20 - X offset