How to initialize a pointer to a structure in C++? -
here defined structure struct structure in class a. class b nested in class a.
class { public: struct structure // structure need { std::vector <std::vector <float>> input; std::vector <int> output; float ft; b* bb; }; private: b b; structure* pstruct; }; now want initialize pointer pstruct before use it.
example, use pstruct->output.push_back().
for example can initialize pointer in default constructor of class. like
class b {}; class { public: a() : b(), pstruct( new structure() ) { pstruct->bb = &b; } struct structure // structure need { std::vector <std::vector <float>> input; std::vector <int> output; float ft; b* bb; }; private: b b; structure* pstruct; };
Comments
Post a Comment