// Example C++ code for OPT// From the test suite of https://github.com/codespecs/daikon// daikon/tests/kvasir-tests/virtual-method#include <stdio.h>class Shape {public:virtual int num_sides() = 0;static bool compare(Shape *s1, Shape *s2);};bool Shape::compare(Shape *s1, Shape *s2) {return s1->num_sides() == s2->num_sides();}class Triangle : public Shape {virtual int num_sides();};class Square : public Shape {virtual int num_sides();};int Triangle::num_sides() {return 3;}int Square::num_sides() {return 4;}int main(int argc, char **argv) {Shape *shapes[10];for (int i = 0; i < 10; i++) {shapes[i] = (i & 1) ? (Shape*) new Triangle() : (Shape *) new Square();}for (int i = 0; i < 10; i++) {printf("Shape %d has %d sides\n", i, shapes[i]->num_sides());}Shape::compare(shapes[0], shapes[1]);Shape::compare(shapes[2], shapes[4]);}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。