Reputation: 6057
I want to build a somewhat flexible inheritance for different HLSL-Shaders. Sadly my planned route did not work, and i am wondering why. Here is what i am doing:
I have a base-struct and some structs which inherit from it:
struct baseStruct {};
struct childStruct1 : public baseStruct {
int someInt1;
int someInt2;
}
struct childStruct2 : public baseStruct {
float someFloat1;
bool someBool1;
}
And an abstract class with pure virtual functions declared like this:
class BaseClass {
virtual void Function1(baseStruct& structVal) = 0;
virtual void Function2(baseStruct& structVal) = 0;
}
This is the according child class:
class ChildClass {
void Function1(baseStruct& structVal);
void Function2(baseStruct& structVal);
}
Now i want to be able to call either of those functions with different structs, which have baseStruct
as a parent like this:
childStruct1 cS1;
cS1.someInt1 = 5;
CS1.someInt2 = -3;
Function1(cS1);
The compiler is not complaining, but when i step through my program i noticed that the struct is filled with values before the function, but as soon as i step into my function the struct is empty. Now my first impression would be, that this happens because it gets "casted" to a baseStruct
, which is empty.
Is there a way to achieve something like this, or am i doing something wrong? Maybe this is even possible and i fucked up somewhere else, but then why does the debugger say its empty?
Thank you!
Upvotes: 0
Views: 771
Reputation: 5230
The struct you see in the debugger is empty because when you enter Function1 the debugger 'forgets' any info about cs1 and knows just about baseStruct (which is empty).
If you do something like
childStruct *cs1 = reinterpret_cast<childStruct1>(&structVal) ;
yoy should see everything there.
But this takes to the real problem of you design: how do you tell, inside Funtion1 if you have received a childStruct1 or childStruct2?
Upvotes: 1