I'm learning C++ by making a Graph class (with Vertex and Edge class as well). I'm having A LOT of errors:
Error 72 error C2039: 'other' : is not a member of '`global namespace'' c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0 167
Error 92 error C2039: 'pointer' : is not a member of 'std::_Wrap_alloc<_Alloc>' c:\program files (x86)\microsoft visual studio 11.0\vc\include\vector 450
Error 98 error C2039: 'pointer' : is not a member of 'std::_Wrap_alloc<_Alloc>' c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0 104
Error 102 error C2039: 'pointer' : is not a member of 'std::_Wrap_alloc<_Alloc>' c:\program files (x86)\microsoft visual studio 11.0\vc\include\vector 458
Error 70 error C2039: 'rebind' : is not a member of '`global namespace'' c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0 167
Error 15 error C2039: 'type' : is not a member of 'std::_Get_pointer_type<_Ty>' c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0 421
Error 18 error C2039: 'type' : is not a member of 'std::_Get_pointer_type<_Ty>' c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0 248
Error 27 error C2039: 'type' : is not a member of 'std::_Get_pointer_type<_Ty>' c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0 255
Error 59 error C2146: syntax error : missing ';' before identifier 'allocate' c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0 874
Error 84 error C2770: invalid explicit template argument(s) for '_Uty::void_pointer std::_Get_void_pointer_type<_Ty>::_Fn(int)' c:\program files (x86)\microsoft visual studio 11.0\vc\include\xmemory0 255
Those are only some of them, there are a lot more (these are in Visual Studio 2012). I have some in Code Blocks as well (I'm trying to debug with both of them)). Here are some of Code Blocks:
error: no matching function for call to 'make_heap(std::vector<std::pair<Vertex<int>*, double>, std::allocator<std::pair<Vertex<int>*, double> > >::iterator, std::vector<std::pair<Vertex<int>*, double>, std::allocator<std::pair<Vertex<int>*, double> > >::iterator, <unresolved overloaded function type>)'
note: candidates are:
note: template<class _RAIter> void std::make_heap(_RAIter, _RAIter)
note: template argument deduction/substitution failed:
note: candidate expects 2 arguments, 3 provided
note: void std::make_heap(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<std::pair<Vertex<int>*, double>*, std::vector<std::pair<Vertex<int>*, double>, std::allocator<std::pair<Vertex<int>*, double> > > >; _Compare = bool (Graph<int>::*)(std::pair<Vertex<int>*, double>, std::pair<Vertex<int>*, double>)]
Here are some snippets of my code that could possibly point to the error's source (I'm not putting all my code here because I saw a topic in Help section saying I shouldn't put too much code, only what is needed):
template <typename T>
class Graph
{
private:
std::vector< Vertex<T>* > m_vVertexes;
int m_nIndexGenerator;
Graph(const Graph& g);
Graph& operator=(const Graph& g);
void Init();
bool Compare(std::pair< Vertex<T>*, double > pFrom, std::pair< Vertex<T>*, double > pTo);
template <typename T>
inline bool Graph<T>::Compare(std::pair< Vertex<T>*, double > pFrom, std::pair< Vertex<T>*, double > pTo)
{
return pFrom.second >= pTo.second;
}
template <typename T>
bool Graph<T>::A_Star(int source, int destiny, double (* Heuristic)(const T& tFrom, const T& tTo), const bool testIfItsOnOpenSet)
{
int vSize = m_vVertexes.size();
bool found = false;
// Checking if it is not out of the bounds
if(source < 0 || destiny < 0 || source >= vSize || destiny >= vSize)
return false;
Vertex<T>* vDestiny = m_vVertexes[destiny];
T& tDestinyInfo = vDestiny->GetInfo();
// Initializing the vectors to proper values
Init();
m_vVertexes[source]->SetCost(0.0);
std::pair< Vertex<T>*, double > pTempFrom;
pTempFrom.second = Heuristic(m_vVertexes[source]->GetInfo(), tDestinyInfo);
pTempFrom.first = m_vVertexes[source];
// Initializing the minHeap
std::vector< std::pair< Vertex<T>*, double > > minHeap;
minHeap.reserve(vSize);
std::make_heap(minHeap.begin(), minHeap.end(), Compare);
minHeap.push_back(pTempFrom);
std::push_heap(minHeap.begin(), minHeap.end(), Compare);
while(!minHeap.empty())
{
std::pop_heap(minHeap.begin(), minHeap.end(), Compare);
pTempFrom = minHeap.back();
minHeap.pop_back();
Vertex<T>* vTempFrom = pTempFrom.first;
vTempFrom->SetColor(Black);
double dCostFrom = vTempFrom->GetCost();
if(vTempFrom == vDestiny)
{
found = true;
break;
}
int fromIndex = vTempFrom->GetIndex();
for(int i = vTempFrom->GetNextAdjacentVertex(); i > -1; i = vTempFrom->GetNextAdjacentVertex())
{
Vertex<T>* vTempTo = m_vVertexes[i];
double dCost = dCostFrom + vTempFrom->GetEdgeCost(vTempTo->GetIndex);
if(testIfItsOnOpenSet && vTempTo->GetColor() == Gray && dCost < vTempTo->GetCost())
{
vTempTo->SetColor(White);
typename std::vector< Vertex<T>*, double >::iterator it = std::find(minHeap.begin(), minHeap.end(), vTempTo); // I only put this typename in there because CodeBlocks was complaining about it, I didn't get it though
minHeap.erase(it);
std::make_heap(minHeap.begin(), minHeap.end(), Compare);
}
I dind't post everything and I didn't even post the entire A_Star algorithm, because I think the mistake is somewhere in what I posted.
Note: all that code is inside a .h file, because if I had the definition in a .cpp file I would have to say which types I wanted for template typename (at least that's what I understood).
@edit
Here is the link to see the entire code if needed: https://github.com/Jordan2R/GraphDebug