当前位置: 技术问答>linux和unix
g++编译不过的模板成员初始化
来源: 互联网 发布时间:2017-04-06
本文导语: template class BinaryHeap { BinaryHeap(int MaxSize) { _Heap.assign(MaxSize + 1, 0); } } class AStar { private: BinaryHeap _binaryHeap; } AStar::AStar(int szMaxNodes/* = 50000 */) :_binaryHeap(szMaxNodes) { } gcc报错. vs编译通过 /usr/inc...
template
class BinaryHeap
{
BinaryHeap(int MaxSize)
{
_Heap.assign(MaxSize + 1, 0);
}
}
class AStar
{
private:
BinaryHeap _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::_M_assign_dispatch(_Integer, _Integer, std::__true_type) [with _Integer = int, _Tp = PathNode*, _Alloc = std::allocator]’:
/usr/include/c++/4.4/bits/stl_vector.h:395: instantiated from ‘void std::vector::assign(_InputIterator, _InputIterator) [with _InputIterator = int, _Tp = PathNode*, _Alloc = std::allocator]’
../PriorityQueue.h:81: instantiated from ‘BinaryHeap::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::_M_fill_assign(size_t, const _Tp&) [with _Tp = PathNode*, _Alloc = std::allocator]’
class BinaryHeap
{
BinaryHeap(int MaxSize)
{
_Heap.assign(MaxSize + 1, 0);
}
}
class AStar
{
private:
BinaryHeap _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::_M_assign_dispatch(_Integer, _Integer, std::__true_type) [with _Integer = int, _Tp = PathNode*, _Alloc = std::allocator]’:
/usr/include/c++/4.4/bits/stl_vector.h:395: instantiated from ‘void std::vector::assign(_InputIterator, _InputIterator) [with _InputIterator = int, _Tp = PathNode*, _Alloc = std::allocator]’
../PriorityQueue.h:81: instantiated from ‘BinaryHeap::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::_M_fill_assign(size_t, const _Tp&) [with _Tp = PathNode*, _Alloc = std::allocator]’
|
貌似楼主的代码不完整啊!代码里没有vector?
|
参数传错了???