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 ..
Category : casting
I created a test below to limit down the problem I have in the actual code base (where I try to make a shared_ptr implementation). I am limited to C++03, no RTTI or Exception handling. (Boost is not an option) I have a templated class A. I want it to be assignable such that I ..
I have newtypes around int, as well as classes that contains those newtype. class IndexA { int i; }; class A { IndexA index; }; // this mimic exactly the hierarchy of `A` struct IndexB { int i; }; struct B { IndexB index; }; Given that A and B share the exact same binary ..
Found this in some old C code.. , looking for an interpretation.. Has anyone ever seen this (*reinterpret_cast<void***>(r9)) Source: Windows Que..
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 ..
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 ..
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; ..
I have a parent class called A, and a subclass called B. B has method printB(); Why can I c-style cast an A pointer to a B pointer and access method printB()? even though A doesn’t have a printB() func? class A { }; class B: public A { public: void printB() { std::cout<<"testB"<<std::endl; } ..
It looks like this code is acceptable with gcc even though the standard states that the value of the expression is discarded in case of a void cast. #include <iostream> int f(int i) { int a = i*2; (void)a; a++; // looks OK even after void cast return a; // looks OK even after void ..
void __fastcall func1(void* ptr, int edxReg) { int a = 5; } I want to take this function’s address and set it to a uintptr_t variable: std::uintptr_t addr = &func1; However, I cannot do this, since it cannot convert from void(__fastcall)(void* , int) to uintptr_t. I tried using C++ style casting, but have had no ..
Recent Comments