简体   繁体   中英

error: ‘class std::vector<route, std::allocator<route> >’ has no member named ‘exitPoint’

Please tell me if some more info is needed here: Global declarations:

    typedef struct route
    {
        int          exitPoint;
        bool         allBranchesTraversed;
    } route;

   ****vector <route> routeVector;****

The culprit func is getting called from:

int main ()
{
....
    do
    {
        ****currentExitPoint = returnShortestWeightedBranch (&routeVector);****
        if (currentExitPoint != -1)
        {
            objRoute.exitPoint = currentExitPoint;          
            routeVector.push_back (objRoute);
        }
        else
        {
          break;
        }
    } while (1);
}

The error is in this func on the line with ** :

int returnShortestWeightedBranch (vector <route> *objRouteVector)
{
....    
    for (unsigned int h = 0; h < objRouteVector->size (); h++)
    {
        // Locate 'currentExitPoint' in the vector 'exitPointDetailsVector'.
        for (i = 0; i < exitPointDetailsVector.size(); i++)
        {       
            // If located
            ****if (objRouteVector[h].exitPoint == exitPointDetailsVector[i].exitPoint)****
            {
                // For all the branches of the 'currentExitPoint',
                for (j = 0; j < exitPointDetailsVector[i].branchesVector.size(); j++)
                {

...............
}

If you use vector <route> *objRouteVector as parameter, you need (*objRouteVector)[h].exitPoint . Better is using reference: vector <route> &objRouteVector .

You took a pointer to objRouteVector, you need to take a reference. Your code indexing objRouteVector isn't indexing the vector at all- it's indexing the pointer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM