本文整理汇总了C++中tvector::capacity方法的典型用法代码示例。如果您正苦于以下问题:C++ tvector::capacity方法的具体用法?C++ tvector::capacity怎么用?C++ tvector::capacity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tvector
的用法示例。
在下文中一共展示了tvector::capacity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mySize
tvector<itemType>::tvector(const tvector<itemType> & vec)
// postcondition: vector is a copy of vec
: mySize(vec.size()),
myCapacity(vec.capacity()),
myList(new itemType[myCapacity])
{
int k;
// copy elements
for(k = 0; k < mySize; k++){
myList[k] = vec.myList[k];
}
}
示例2:
const tvector<itemType> &
tvector<itemType>::operator = (const tvector<itemType> & rhs)
// postcondition: normal assignment via copying has been performed;
// if vector and rhs were different sizes, vector
// has been resized to match the size of rhs
{
if (this != &rhs) // don't assign to self!
{
delete [] myList; // get rid of old storage
myCapacity = rhs.capacity();
mySize = rhs.size();
myList = new itemType [myCapacity]; // allocate new storage
// copy rhs
int k;
for(k=0; k < mySize; k++)
{
myList[k] = rhs.myList[k];
}
}
return *this; // permit a = b = c = d
}