I have a class that does an implementation of a graph (template class) in C++ (I didn’t make this), and basically what I want to do is have a representation of Places (they are my vertices) and my edges (that link them) are distances (in miles).
I declared a simple Graph<Places *, double> places; and now I’m creating a method that checks check if a certain Place is already in the graph in order to avoid duplicates. My graph has a method Vertice<TV,TR>* findvert_content(const TV& v) const; that returns a pointer of an vertice it finds (so if that returning pointer is valid, I’m assuming it exists in the graph). Now I want to do this in my Test class:
bool Test::verifiesName(Place *place) {
Vertice<Place *, double> find_place = places.findvert_content(*place);
...
}
The problem is it gives me an semantic issue: “No viable conversion from ‘Place’ to ‘Place *const'” and I don’t know what to do from here.
Here is the code of my findvert method (for reference):
template<class TV,class TR>
Vertice<TV,TR>* Graph<TV,TR>::findvert_content(const TV& v) const
{
Vertice<TV,TR>* ap=graf;
while (ap != NULL)
{
if (ap->vcontent == v)
return ap ;
else
ap=ap->apvertice;
}
return ap;
}
P.S. graf is just an attribute in my Graph class: Vertice<TV,TR>* graf;.
*placeis the value at the address whereplacepoints to. Are you sure you want to pass the value and not the pointer itself when you call the method? Like:Also, why do you need the & if you are not modifying
vinside the method? Then declareand it should be compatible with the above call.