g++编译不过的模板成员初始化
template<class T>
class BinaryHeap
{
BinaryHeap(int MaxSize)
{
_Heap.assign(MaxSize + 1, 0);
}
}
class AStar
{
private:
BinaryHeap<PathNode> _binaryHeap;
}
AStar::AStar(int szMaxNodes/* = 50000 */)
:_binaryHeap(szMaxNodes)
{
}
gcc报错.
vs编译通过
/usr/include/c++/4.4/bits/stl_vector.h: In member function ‘void std::vector<_Tp, _Alloc>::_M_assign_dispatch(_Integer, _Integer, std::__true_type) [with _Integer = int, _Tp = PathNode*, _Alloc = std::allocator<PathNode*>]’:
/usr/include/c++/4.4/bits/stl_vector.h:395: instantiated from ‘void std::vector<_Tp, _Alloc>::assign(_InputIterator, _InputIterator) [with _InputIterator = int, _Tp = PathNode*, _Alloc = std::allocator<PathNode*>]’
../PriorityQueue.h:81: instantiated from ‘BinaryHeap<T>::BinaryHeap(int) [with T = PathNode]’
../AStar.cpp:38: instantiated from here
/usr/include/c++/4.4/bits/stl_vector.h:1051: error: invalid conversion from ‘int’ to ‘PathNode*’
/usr/include/c++/4.4/bits/stl_vector.h:1051: error: initializing argument 2 of ‘void std::vector<_Tp, _Alloc>::_M_fill_assign(size_t, const _Tp&) [with _Tp = PathNode*, _Alloc = std::allocator<PathNode*>]’
貌似楼主的代码不完整啊!代码里没有vector?
参数传错了???
因为:
void std::vector::assign( size_type count, const T& value );
所以:
_Heap.assign(MaxSize + 1, 0);
===>
_Heap.assign(MaxSize + 1, (T *)0);
_Heap.assign(MaxSize + 1,(T *)NULL);
这样就行了