C++ (Qt)typedef double Matrix[16];void InvertMatrix( Matrix & dst, Matrix src );
C++ (Qt)#include <QCoreApplication> const std::size_t NR = 5;const std::size_t NC = 10; typedef int m1[NC];typedef m1 Matrix[NR]; void InvertMatrix(Matrix &dst, Matrix src) { } int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); Matrix matrix; return a.exec();}
C++ (Qt)#ifndef SHAPE_H#define SHAPE_H #include <vector>#include <utility> namespace myShapes { class Shape{public: // ... std::pair<int, int> point(int index) const { return m_points[index]; } protected: void addPoint(int x, int y) { m_points.push_back(std::make_pair(x, y)); } private: std::vector<std::pair<int, int> > m_points; //...}; } #endif // SHAPE_H
C++ (Qt)#ifndef VIEWER_H#define VIEWER_H #include <QGLWidget>#include "shape.h" #include <vector> class Viewer : public QGLWidget{public: Viewer(QWidget *pwgt = 0); void addForPainting(const myShapes::Shape &ps) { m_shapes.push_back(ps); } protected: virtual void initializeGL(); virtual void resizeGL(int nWidth, int nHeight); virtual void paintGL(); private: std::vector<myShapes::Shape> m_shapes;}; #endif // VIEWER_H
C++ (Qt)int main(int argc, char *argv[]){ QApplication a(argc, argv); Viewer viewer; viewer.resize(400, 200); myShapes::Shape *pr1 = new myShapes::Rectangle(5.0, 10.0); myShapes::Shape *pr2 = new myShapes::Rectangle(5.0, 10.0); myShapes::Shape *pr3 = new myShapes::Rectangle(5.0, 10.0); myShapes::Shape *pr4 = new myShapes::Rectangle(5.0, 10.0); myShapes::Shape *pr5 = new myShapes::Rectangle(5.0, 10.0); viewer.addForPainting(*pr1); viewer.addForPainting(*pr2); viewer.addForPainting(*pr3); viewer.addForPainting(*pr4); viewer.addForPainting(*pr5); delete pr1; delete pr2; delete pr3; delete pr4; delete pr5; viewer.show(); return a.exec();}
C++ (Qt)#include <QCoreApplication>#include <memory>#include <vector>#include <string>#include <iostream> //----------------- class Shape -----------------class Shape {public: Shape() { } virtual ~Shape() { } const std::string& name() const { return m_name; } protected: std::string m_name;}; //----------------- class Rectangle -------------class Rectangle : public Shape{public: Rectangle() { m_name = "Rectangle"; }}; //----------------- class Circle -------------class Circle : public Shape{public: Circle() { m_name = "Circle"; }}; //----------------- class Viewer -------------class Viewer {public: void addForPaiting(std::shared_ptr<Shape> pshape) { m_pshapes.push_back(pshape); } void showShapes() const { for (std::size_t i = 0; i < m_pshapes.size(); ++i) { std::cout << "Name of the Shape: " << m_pshapes[i]->name() << std::endl; } } private: std::vector<std::shared_ptr<Shape> > m_pshapes;}; int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); std::shared_ptr<Shape> pr(new Rectangle); std::shared_ptr<Shape> pc(new Circle); Viewer viewer; viewer.addForPaiting(pr); viewer.addForPaiting(pc); viewer.showShapes(); return a.exec();}
C++ (Qt) std::vector<std::pair<int, int> > m_points;
C++ (Qt) typedef std::pair<int, int> TPoint; typedef std::vector<TPoint> > TVector; TVectot m_points;