Computer Programming - strona 5

note /search

Constructing and destructing dynamic objects

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 266

Constructing and destructing dynamic objects point *pp0=new point; point *pp1=new point(1.0); point *pp2=new point(10.0, 20.0); point *arrPoints=new point[10]; // array of 10 points // initialized with the default constructor // in order of increasing addresses // new T[] - calls only the default c...

Defining

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 497

Defining class point { double x, y; public: // … point(double, double); point(double); point() { x = y = 0.0; }; }; inline point::point(double d) { x = y = d; } point::point(double x0, double y0) { x = x0; y = y0; } ...

Destructor - Example

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 490

Destructor  Called when the object is destroyed  Necessary if something should be done at this timepoint  Destructor for the class T: ~T();  Example ~point() // no args, no returned value ...

Example of default function argument

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 371

Default function arguments int fun(int i1, int i2=20, int i3=30);  starting from the first default argument, all remaining also have to be default  function with default arguments is not overloaded, &fun(int) == &fun(int, int)  we may overload: int fun(int i1, int i2); // declaration is ...

Goto

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 623

Goto  more restrictions than in C: - cannot jump over initialization (in C initializations are always before goto-s…) - … this function is wrong: void fn(void) { goto end; int i = 1; end: ; } ...

Hermetization and encapsulation

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 420

Hermetization and encapsulation encapsulation - defining all data and methods in single class hermetization - restricting access to class members  All class members are private by default  OOOP — orthodox OOP: - all class data members are private - we access them from outside through class method...

Inheritance

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 497

Inheritance  Reveals hierarchic relations between classes  To develop (extend) existing classes without need to modify or recompile them  Reusability of code (one defines only what is added or changed, all the rest is reused)  Base class p...

Inline functions

  • Politechnika Śląska
  • Computer Programming
Pobrań: 7
Wyświetleń: 448

Inline functions inline int sum(int a, int b) { return a+b; }  places the code in place where it is called  many copies in case of many calls  destined to replace macro definitions  inline keyword is only a recommendation for the compiler  au...

Many objects

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 504

Many objects  Usually many objects are similar - with the same set of features  We define the set only once and use it many times  class — a group of items, things etc., possessing some features in common  We need one class for all similar objects ...

Member access operator

  • Politechnika Śląska
  • Computer Programming
Pobrań: 0
Wyświetleń: 462

Member access operator - T* operator-();  T t;  t-m is interpreted as: ( t.operator- )-m  we may use object as if it were a pointer  if operator- returns no pointer, then - we still may use it: a=t.operator-(); - we cannot do: a=t-; it's a syn...