毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> linux >> 正文

g++编译不过的模板成员初始化

更新时间:2013-4-7:  来源:毕业论文

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);
这样就行了

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。