Computer Programming - strona 6

note /search

Object

  • Politechnika Śląska
  • 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
  • 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
  • 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
  • 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...

Structures and classes

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

Structures and classes  Initialization in braces { } is valid only for classes: - whose all fields are public - that have no explicit constructor struct s_xy { int x, y; }; s_xy sxy={10,20}; // ok //s_xy sxy1(10,10) - bad! struct xy { int x,y; x...

The default constructor

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

The default constructor  If no constructors were declared, the compiler generates a default constructor  It is a constructor with no arguments, of an empty body, for the T class: T::T() { }  If we declare any constructor (even constructor with args) then compiler does not generate the default co...

This

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

This  exists in every non-static method  a pointer to the object, for which the method was called  used for returning reference or pointer to the object for which the method was called  does not occupy

Type void

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

Type void *  no automatic conversion to other pointer types void *malloc(size_t size); char *str; int *pi; str = (char *) malloc(10); pi = (int *)malloc(100);  automatic conversion from almost any pointer type (exception: const *, volatile *) vo...

Unions

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

Unions  In C++ a union is a class, but: - It cannot contain objects with constructors or destructors defined - There can be no access restrictions - all the fields are public - It cannot inherit from a class ...

Why to inherit

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

Why to inherit? class person { char * name, * surname; public: void print_name (); void print_surname(); void print_all(); } class adult { char * name, * surname, * ID_card; public: void print_name(); void print_surname(); void print_ID_card(); void print_all(); } class person { char * name, * surn...