本文整理汇总了C++中XList::pushElementToBack方法的典型用法代码示例。如果您正苦于以下问题:C++ XList::pushElementToBack方法的具体用法?C++ XList::pushElementToBack怎么用?C++ XList::pushElementToBack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XList
的用法示例。
在下文中一共展示了XList::pushElementToBack方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
srand((unsigned) time(NULL));
try {
XList<Shape*> list;
// filling list of figures with random figures of all types.
int numberOfElements = rand() % 100;
for(int i = 0; i < numberOfElements; i++) {
switch (i % 5) {
case 0:
list.pushElementToBack(new Point("TestPoint", rand() % 100, rand() % 100));
break;
case 1:
list.pushElementToBack(new Circle("TestCircle", rand() % 100, rand() % 100, rand() % 100));
break;
case 2:
list.pushElementToBack(new Rect("TestRect", rand() % 100, rand() % 100, rand() % 100, rand() % 100));
break;
case 3:
list.pushElementToBack(new Square("TestSquare", rand() % 100, rand() % 100, rand() % 100));
break;
case 4:
Polyline* pol = new Polyline("TestPol");
Point p1("pol_point_1", rand() % 100, rand() % 100);
Point p2("pol_point_2", rand() % 100, rand() % 100);
Point p3("pol_point_3", rand() % 100, rand() % 100);
pol->addPoint(p1);
pol->addPoint(p2);
pol->addPoint(p3);
list.pushElementToBack(pol);
break;
}
}
std::cout << "Number of shapes " << Shape::getNumberOfShapes() << "\n";
XList<Shape*>::Iterator it = list.begin();
for(it = list.begin(); it != list.end(); ++it) {
std::cout << "\n" << **it << "\n";
}
std::cout << "Number of shapes " << Shape::getNumberOfShapes() << "\n";
for(it = list.begin(); it != list.end(); ++it) {
delete *it;
}
// should be zero
std::cout << "Number of shapes " << Shape::getNumberOfShapes() << "\n";
return 0;
} catch (std::exception ex) {
std::cerr << ex.what();
return 1;
}
}