i know value classes don't have default constructor compiler initializes elements in class zero. arrays in value class not initialized:
value class c_locationval { public: double x, y, z; c_locationval(double i_x, double i_y, double i_z) {x = i_x; y = i_y; z = i_z;} }; typedef cli::array<c_locationval> arrloc; value class c_managed { public: arrloc^ m_aloctest; //c_managed() { m_aloctest = gcnew arrloc(3); } --> not permitted double funcmanaged () { return m_aloctest[0].x; --> error: object reference not set instance of object } }; i cheat , use:
c_managed(int i) { m_aloctest = gcnew arrloc(3); } but there must solution.
can please tell me how solve this?
a value class initialized "null/0". managed reference in value class initialized "null". if want have special initialization, have solution, pointing out: need create special constructor has parameters "initialize" value class correctly.
the question is: need value class contains managed reference??? should ref class.
also, happens, if value class copied? should happen reference? directly copied! intended? goal of value class provide "real" copy! in case not "fully copied"...
pleas re-think if value class best solution data storage...
Comments
Post a Comment