c++ - Use base struct as function argument in inheritance scenario -


i want build flexible inheritance different hlsl-shaders. sadly planned route did not work, , wondering why. here doing:

i have base-struct , structs inherit it:

struct basestruct {};  struct childstruct1 : public basestruct {     int someint1;     int someint2; }  struct childstruct2 : public basestruct {     float somefloat1;     bool somebool1; } 

and abstract class pure virtual functions declared this:

class baseclass {     virtual void function1(basestruct& structval) = 0;     virtual void function2(basestruct& structval) = 0; } 

this according child class:

class childclass {     void function1(basestruct& structval);     void function2(basestruct& structval); } 

now want able call either of functions different structs, have basestruct parent this:

childstruct1 cs1; cs1.someint1 = 5; cs1.someint2 = -3;  function1(cs1); 

the compiler not complaining, when step through program noticed struct filled values before function, step function struct empty. first impression be, happens because gets "casted" basestruct, empty. there way achieve this, or doing wrong? maybe possible , fucked somewhere else, why debugger empty? thank you!

the struct see in debugger empty because when enter function1 debugger 'forgets' info cs1 , knows basestruct (which empty).

if

childstruct *cs1 = reinterpret_cast<childstruct1>(&structval) ; 

yoy should see there.

but takes real problem of design: how tell, inside funtion1 if have received childstruct1 or childstruct2?


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -