Politechnika Śląska - strona 146

Conversion derived - base

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

Conversion derived - base  The conversion from ”pointer to derived” to ” pointer to base” is allowed and automatic without explicit cast operator  … if inheritance was public - Why only one-wa...

Conversion operator

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

Conversion operator  a.k.a. conversion function / method,  it converts object of its own class to other class T::operator X();  Conversion operator of class T to the X type: - no return value specified, - no argument(s) specified, - declared as a class method  example: person::operator int(); ...

Copy constructor in derived class

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

Copy constructor in derived class  It is a constructor so: - Remember the order of constructors: base class(es) constructor(s) will always run - One may supply parameters for base class constructor at initiation list - Remember: also member objects will be constructed class derived:public base { ....

Copy constructor

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

Copy constructor  Used for initializing objects using other objects of the same class, for the T class: T::T(const T &);  Parameter has to be a reference; otherwise temp. object would be created, that should also be somehow initialized - with the copy constructor!  Parameter should be const ...

Declarations are statements in C++

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

Declarations are statements in C++  declaration inside block is a statement  it may be placed after other statements { int i=12; cout ...

Default function arguments

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

Default function arguments void line(int len, char c='*') { for (int i=0; i...

Defining methods

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

Defining methods  Inside class declaration class person { … void input() { cinageFNameLName; } // semicolon not required … };  a method defined inside a class declaration is inline by default  outside of the class: - use the scope operator - by default, such method is not inline void person :: s...

Derived class

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

Derived class  adult contains fields and methods: char * name, * surname — inherited, inaccessible for the class adult char *nr_ID_card — private in adult print_name(), print_surname () — public, inherited from person person::print_all() — public, inherited, hidden: use scope operator (::) to acce...

Friend

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

Friend  by declaring a ”friendly” code we allow accessing protected and private members of the class class A { friend C::theMethodNoArg(); // specific method (if overloaded, then with specific args) friend class B; // concerns whole declaration of...

Initialization list

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

Initialization list  in a definition of a constructor (and only there) we may use an initialization list T() : member(initializer) [, member(initializer) …] { } class point { double x, y; public: // … point():x(0.0), y(0.0) {}; }; inline point::point(double d) :x(d), y(d) { // all done } point::po...