0

我正在尝试用动态创建的结构元素填充结构向量。下面的所有代码都包含在一个名为 TD_Dijkstra_OS 的类中

结构:

struct instFunDescLeg
 {
float Ap, Bp, tfail;
typename GraphType::NodeIterator n; //external library data type 
};

我计算需要在项目的字段中分配到函数中的值:

           v = G.target( e);

            FunDataType Ap, Bp, offset, slope;

    v->dist = getEarliestArrivalTime( e, u->dist, slope, offset); //TEST
            //if( getEarliestArrivalTime( e, u->dist, slope, offset) != v->dist)
            //    continue;

            Ap = ( 1 + slope) * u->Ap;
            Bp = ( 1 + slope) * u->Bp + offset;

            if( v->timestamp != (*m_timestamp))
            {
                v->Ap = Ap;
                v->Bp = Bp;

                Q.push( v);
                v->timestamp = (*m_timestamp);
            }

            else
            {
                if( Ap < v->Ap)
                {
                    v->Ap = Ap;
                    v->Bp = Bp;
                }

                else if( Ap == v->Ap && Bp > v->Bp)
                    v->Bp = Bp;
            }
            v->tfail = v->dist;
            storeInstFunDescLeg(v);

然后我创建一个结构项目并尝试将其插入到 instFunDescLeg 项目的向量中,声明为:

  std::vector<struct instFunDescLeg> bp;

进入这个功能:

 void storeInstFunDescLeg(const NodeIterator& u)
{
//representation: (idn:(Ap(tfail),Bp(tfail),idfn(tfail))), for a node identified by idn
//store into a vector
instFunDescLeg* leg;
leg = new instFunDescLeg();

leg->Ap = u->Ap;
leg->Bp = u->Bp;
leg->tfail = u->tfail;
leg->n = u;

bp.push_back(leg);
}

当我编译它时,我收到一条错误消息,指出没有匹配 bp.push_back(leg) 的函数。错误消息后的注释说明了这种情况:

 /usr/include/c++/4.6/bits/stl_vector.h:826:7: σημείωση:   no known conversion for 
 argument 1 from ‘TD_Dijkstra_OS<DynamicGraph<AdjacencyListImpl, node, edge> 

::instFunDescLeg*' 到 'const value_type& {aka const TD_Dijkstra_OS >::instFunDescLeg&}'

有人可以帮我执行插入程序吗?

4

1 回答 1

2

std::vector<struct instFunDescLeg> bp;应该写std::vector<instFunDescLeg> bp;

您的结构相当简单,因此我认为无需使用您提供的内容存储指向它的指针向量。如果有一些隐藏的要求会迫使您使用指针,请尝试将它们隐藏在智能指针类后面(例如unique_ptr)。

于 2013-09-10T16:38:57.783 回答