2

... this is my sample code:

struct QfeelSLAMNode {
    int mnNodeID;
    float mX,mY,mTheta;
    bool mbIsLandmark;
};

std::vector<Nodes>m_nodes;
std::vector<const Qflat::slam_node*> f_node;

    for (auto it = m_nodes.cbegin();it != m_nodes.cend();it++){
        Qflat::slam_node  node(it->mnNodeID,it->mX,it->mY,it->mTheta,it->mbIsLandmark);
        f_node.push_back(&node);
    }
    auto test_flat = builder.CreateVectorOfStructs(f_node.begin().base(),f_node.size());

    auto table = Qflat::CreateFbVTDataNodes(builder,node_data_type,testv2);

but when I create table ,I get this error:

No viable conversion from 'Offset<Vector<const Qflat::slam_node *const *>>' to 'Offset<Vector<const Qflat::slam_node *>>'

I don't why it happen. Any help on this issue would be greatly appreciated

大陸北方網友
  • 3,696
  • 3
  • 12
  • 37
lai
  • 21
  • 1

1 Answers1

0

First, you're adding a pointer to a local variable that is about to go out of scope to a vector in push_back. That's a dangling pointer. Don't ever do that in any C++ code, whether using FlatBuffers or not.

Second, the error already indicates the problem: the function expects a value type and you're supplying a pointer. So remove the * and the & from the code above.

Aardappel
  • 5,559
  • 1
  • 19
  • 22
  • Sorry I found the reason for my mistake yesterday, which is consistent with the reason you said Thank you very much for your reply – lai Sep 10 '20 at 02:39