C class point public point int draw private
Описания класса C++ class point { public: point(); int draw(); private: Int x, y; }; point: : point() { } int point: : draw() { } class point { public: point() { … } int draw() { … return 0; } private: Int x, y; }; point: : point() { } inline int point: : draw() { } 17. 09. 2020 ВГУЭС 5
Статические члены и методы C++ class point { public: point (int x 1, int y 1) static void set_zero(); private: int x, y; static point zero; static int flag; }; point zero(0, 0); point z, z 1; z. flag Z 1. flag point: : flag z. zero Z 1. zero point: : zero Int point: : flag=0; 17. 09. 2020 ВГУЭС 7
Статические члены и методы. Java class point { public point (int x 1, int y 1) {} public static void set_zero() {} private int x, y; private static point zero; private static int flag; static private float xx[]=new float [100]; public static void main(String [] args) { zero=new point (0, 0); flag=0; point a=new point(2, 3); } } 17. 09. 2020 ВГУЭС 8
Статические члены и методы. Java class point { public point (int x 1, int y 1) {} public static void set_zero() {} private int x, y; private static point zero; private static int flag; static private float xx[]=new float [100]; public static void main(String [] args) { flag=0; point a=new point(2, 3); } static { } 17. 09. 2020 zero=new point (0, 0); ВГУЭС }// 9
Константные члены C++ class point { const int a; int x, y; public : point(): a(10) {} void print() const { cout << “ a=“ << a; } void f() const { x=1; } // error void p() const { inc(y); } // error void inc(const int &zz) { x+=zz; } }; 17. 09. 2020 ВГУЭС 10
Константные члены Java class point { final private int a=1; private int x, y; public point() {} public int print() { a=2; } // error } 17. 09. 2020 ВГУЭС 11
Ключевое слово this class point { int x, y; public: point() {} point inc() { x++; y++; return *this; } void print() { cout << this->x << “”; } class point { private int x, y; public point() {} public point inc() { x++; y++; return this; } public void print() { System. println(this. x); } } }; 17. 09. 2020 ВГУЭС 12
Конструкторы C++ class point { int x, y; public: point() : x(0), y(0){} // конструктор по умолчаню point (int x 1, int y 1): x(x 1), y(y 1) { } point (int x 1, int y 1=0): x(x 1), y(y 1) { } point (int x 1=1, int y 1=1): x(x 1), y(y 1) { } void print() { } }; point z, z 1(10, 20), z 2(11), z 3; z. print(); point *q=new point, *q 1, *q 2; q->print(); q 1=new point(20); q 2=new point(21, 33); 17. 09. 2020 ВГУЭС 13
Конструкторы Java class point { private int x, y; public point() { x=0; y=0; } public point (int x 1, int y 1) { x=x 1; y=y 1; public point (int x 1) { x=x 1; y=10; } public void print () { } }; } point z, z 1; z=new point(); z=new point(1); z=new point (11, 22); z. print(); 17. 09. 2020 ВГУЭС 14
Деструкторы C++ class point { int x, y; public: point() : x(0), y(0){} // конструктор по умолчаню point (int x 1, int y 1=0): x(x 1), y(y 1) { } void print() { } ~point() {} }; point z, z 1(10, 20), z 2(11), z 3; z. print(); point *q=new point, *q 1, *q 2; q->print(); q 1=new point(20); q 2=new point(21, 33); 17. 09. 2020 ВГУЭС 15
Описание класса C++ class vector { int *x, n; static int num; public: vector(): n(0) { x=null; num ++; } vector(int n 1) { x=null; x=new int[n 1]; n=n 1; num++; for(int i=0; i<n; i++) x[i]=0; } ~vector() { delete [] x; x=null; num--; } static int get. Num() { return num; } }; int vector: : num=0; vector z(10), s, *d=new vector[2]; cout << vector: : get. Num(); // 4 ВГУЭС 17. 09. 2020 16
Описание класса Java class vector { private int x[], n; public vector() { x=null; n=0; } public vector(int n 1) { x=null; x=new int[n 1]; n=n 1; for(int i=0; i<n; i++) x[i]=0; } public int get. N () { return n; } }; vector z; z=new vector; System. println(z. get. Num()); // vector. get. Num(); z=new vector(10); 17. 09. 2020 ВГУЭС 17
Массивы объектов C++ class point { int x, y; public: point() { x=y=0; } point(int x 1, int y 1): x(x 1), y(y 1) { } ~point() {} void print() { } }; point s[10]; point *d=new point [10]; point **f; f=new * point[10]; for(int i=0; i<10; i++) f[i]=new point (i, i+1); 17. 09. 2020 ВГУЭС f[0]->print(); for(int i=0; i<10; i++) delete f[i]; delete []f; 18
Массивы объектов Java public class point { private int x, y; public point() { x=y=0; } public point(int x 1, int y 1) { x=x 1; y=y 1; } public void print() { } }; public class A { public void init () { point d[]=new point [10]; for(int i=0; i<10; i++) d[i]=new point (i, i+1); d[0]. print(); } } 17. 09. 2020 ВГУЭС 19
Конструктор копирования C++ class vector { int *x, n; public: vector(): n(0) { x=null; num ++; } vector(int n 1) { x=null; x=new int[n 1]; n=n 1; num++; for(int i=0; i<n; i++) x[i]=0; } vector(const vector &v) { x=null; n=0; x=new int [v. n]; n=v. n; for(int i=0; i<n; i++) x[i]=0; } ~vector() { delete [] x; x=null; num--; } }; vector f(vector p); vector z; 17. 09. 2020 vector z 1=f(z); ВГУЭС 20
- Slides: 20