我想在结构中重载+运算符以实现串联运算符。为此,我需要访问插入该结构的一些类成员(matrix
和route
),如下面的代码所示。
MLP.h
class MLP{
private:
std::vector<int> route;
std::vector<std::vector<tCost>> cost;
double **matrix;
...
}
Structures.h
typedef struct subsequenceCost{
int w;
double t;
double c;
int first,
last;
subsequenceCost operator+(const subsequenceCost& other) const{
return subsequenceCost{
w + other.w,
t + matrix[route[last]][route[other.first]] + other.t,
c + other.w*(t + matrix[route[last]][route[other.first]]) + other.c,
first,
other.last,
};
}
}tCost;
我已经尝试过extern
我将使用的MLP对象,并将subsequenceCost
结构声明为friend
,以便可以访问其私有成员,但没有用因为MLP是tCost
的组成。关于如何做的任何想法?