Here is a defined structure struct structure
in a class A
. Class B
is nested in Class A
.
class A
{
public:
struct structure // the structure I need
{
std::vector <std::vector <float>> Input;
std::vector <int> Output;
float ft;
B* bb;
};
private:
B b;
structure* pStruct;
};
Now I want to initialize the pointer pStruct
before I use it.
For example, I use pStruct->Output.push_back()
.
答案 0 :(得分:0)
For example you can initialize the pointer in the default constructor of the class. Something like
class B {};
class A
{
public:
A() : b(), pStruct( new structure() ) { pStruct->bb = &b; }
struct structure // the structure I need
{
std::vector <std::vector <float>> Input;
std::vector <int> Output;
float ft;
B* bb;
};
private:
B b;
structure* pStruct;
};