int キーと type の値を持つマップを含む street_map というクラスがありますvector<edge>
。メソッドの 1 つで、値へのポインタを初期化してvector<edge>
その内容を取得しようとしています。
class street_map {
public:
explicit street_map (const std::string &filename);
bool geocode(const std::string &address, int &u, int &v, float &pos) const;
bool route3(int source, int target, float &distance) const {
auto it = adjacencyList.find(source);
vector<edge>* v = &(it->second);
return true;
}
private:
unordered_map<side , vector<segment>> map;
unordered_map<int, vector<edge>> adjacencyList;
};
行vector<edge>* v = &(it->second);
はエラーを与えます:
Cannot initialize a variable of type 'vector<edge> *' with an rvalue of type 'const std::__1::vector<edge, std::__1::allocator<edge> > *'
エッジクラスは次のとおりです。
class edge {
int node;
string street;
float length;
int startingNode;
public:
edge(int startingNode, int node, string street, float length) {
startingNode = startingNode;
node = node;
street = street;
length = length;
}
};
これが const キーワードによるものなのか、const キーワードによるものである場合の修正方法を考えています (const キーワードを保持することになっていますが、他に解決策がない場合はそれを取り除くことができると思います)。