C++ 如何在我的代码中获得相同结构的结构中的引用
我有这个结构,但当我提到对其自身类型的引用时,我会遇到一些错误:C++ 如何在我的代码中获得相同结构的结构中的引用,c++,struct,C++,Struct,我有这个结构,但当我提到对其自身类型的引用时,我会遇到一些错误: struct Point { int x; int y; bool isLattice; Vect2D gradient; ///used only when isLattice is false Point p00; ///top-left corner
struct Point {
int x;
int y;
bool isLattice;
Vect2D gradient;
///used only when isLattice is false
Point p00; ///top-left corner
Point p01; ///top-right corner
Point p10; ///bottom-left corner
Point p11; ///bottom-right corner
///the displacement vectors Gradient-this.Vect2D
Vect2D disp00;
Vect2D disp01;
Vect2D disp10;
Vect2D disp11; ///used along the gradient vector of the lattice points
///the Q-s for each corner Q= Disp*G which are going to be used for the interpolation
double q00;
double q01;
double g10;
double q11;
};
我需要知道我应该如何初始化这个结构,因为我过去在其他代码中就是这样做的。这个错误是什么?我猜您来自托管语言
struct Point {
//...
Point p00;
// ...
}
这是你的问题。C++中的对象是<强>不>强>引用。这会将点的实例放在点的实例中。那怎么办?您可以使用指针或引用
改变
Point p00;
到
或许
std::shared_ptr<Point> p00;
std::shared_ptr p00;
改变点pX代码>至点*pX代码>
这样,代码将被编译,而您
开始使用适当的构造函数初始化点指针。为什么不在点实例中使用另一个类型的结构?我想告诉我们错误是什么,以及如何初始化它会有很多问题?例如,当我尝试初始化点p00时,它说它有不完整的字体,你一定是用另一种语言写的。这样的结构在C++中是无限大的。如果你还没有,就把你知道的任何语言都忘记了。我会在代码< STD::SyrdYpPTR < /C> >上引用<代码> STD::UnQuyGyPTR <代码>。似乎不需要共享所有权。@user4581301在我看来,指针来自其他地方,所以所有权不清楚。
std::shared_ptr<Point> p00;