Politechnika Śląska - strona 309

Goto

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • 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
  • dr inż. Piotr Fabian
  • Computer Programming
Pobrań: 0
Wyświetleń: 413

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
  • dr inż. Piotr Fabian
  • Computer Programming
Pobrań: 0
Wyświetleń: 490

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
  • dr inż. Piotr Fabian
  • Computer Programming
Pobrań: 0
Wyświetleń: 441

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
  • dr inż. Piotr Fabian
  • 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
  • dr inż. Piotr Fabian
  • 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...

Object

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Computer Programming
Pobrań: 0
Wyświetleń: 511

Object  Common understanding of ”object”  ” Object” in programming - represents real-life or abstract objects - is a generalized variable (structure) - is a being defined and used according to syntactic and semantic rules of the programming language  Structure - set of data elements, usually of ...

Operators for accessing class members

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Computer Programming
Pobrań: 0
Wyświetleń: 413

Operators for accessing class members  dot ” . ” object.variable; // just like in a C structure object.method(); // encapsulation  scope operator ” :: ” class::variable; // sizeof, static variables class::method(); // defining methods, static methods  Scope definition (object. and class::) usual...

Prototypes of functions

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Computer Programming
Pobrań: 0
Wyświetleń: 455

Prototypes of fun ctions  Function prototypes are required!!! (return value, name, arguments)  In C: a prototype int f() is assumed, in C++ not  #include ”foo_prototypes.h”  void foo(); … foo(); … void foo() {}; ...

References

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Computer Programming
Pobrań: 0
Wyświetleń: 455

References reference to type T: T&  it is a pointer that looks like a variable int i=7, // variable int & iref=i; // reference must be initialized // i.e. associated with something (i) iref++; // now i==8  may be misleading  avoid funct...