Category : casting

Weapon inherits from Item. weapon is a member of class Hero. I want to swap it with the item passed in the function, which is also a Weapon for this example (I’ll add more cases). void Hero::equip(Item* item){ if(instanceof<Weapon>(item)){std::swap (item, static_cast<Item>(weapon));} } Basically, when something is equipped from the hero’s inventory, I want it to ..

Read more

In some places in my code, I use the _mm_prefetch function, which takes in a const char * and int. The first parameter being the memory address of the object to prefetch. Since it’s a const char * instead of void*, it needs to be cast. Note: in the below context nextActive is a pointer ..

Read more

I’m creating unit test for a function that receives a memory address as an unsigned long Inside the function, this addres is reinterpret_casted into a pointer of one of ur classes. void my function(Address inputAdress ) // Address comes from: typedef unsigned long Address; { ClsMyClassThread* ptr = reinterpret_cast<ClsMyClassThread*>(inputAdress); if(ptr == nullptr) { // Do ..

Read more

hope you’ll help me to understand. I have a class, that defines a buffer: typedef std::variant<signed char, unsigned char, short, unsigned short, int, unsigned int, float> BufferData; struct BufferAttribute { unsigned int index; int size = 4; char format = ATTRIBUTE_FORMAT::FLOAT; bool normalized = false; int stride = 0; int offset = 0; std::vector<BufferData> data; ..

Read more