Commit bc59b51ad6b3ad796f4c3f789dd084fda1a8ec95

Authored by Grzegorz Jabłoński
1 parent 982549f4

Casting examples

examples10/05-ptrconv/makefile 0 → 100644
  1 +all: ptrconv1 ptrconv2
  2 +
  3 +ptrconv1: ptrconv1.cpp
  4 + g++ -g -Wall -pedantic $^ -o $@
  5 +
  6 +ptrconv2: ptrconv2.cpp
  7 + g++ -g -Wall -pedantic $^ -o $@
  8 +
  9 +.PHONY: clean
  10 +
  11 +clean:
  12 + -rm ptrconv1 ptrconv2
... ...
examples10/05-ptrconv/ptrconv1.cpp 0 → 100644
  1 +class A {
  2 + int a;
  3 +};
  4 +
  5 +class B {
  6 + int b;
  7 +};
  8 +
  9 +class C : public A, public B
  10 +{
  11 + int c;
  12 +};
  13 +
  14 +int main()
  15 +{
  16 + C c;
  17 +
  18 + A* aptr = &c;
  19 + B* bptr = &c;
  20 +}
  21 +
... ...
examples10/05-ptrconv/ptrconv2.cpp 0 → 100644
  1 +class A {
  2 +public:
  3 + int a;
  4 +};
  5 +
  6 +class B : virtual public A {
  7 + int b;
  8 +};
  9 +
  10 +class C : virtual public A {
  11 + int c;
  12 +};
  13 +
  14 +class D: public B, public C
  15 +{
  16 + int d;
  17 +};
  18 +
  19 +class E: public C, public B
  20 +{
  21 + int e;
  22 +};
  23 +
  24 +int main()
  25 +{
  26 + D d;
  27 + E e;
  28 +
  29 + C* cptr1 = &d;
  30 + C* cptr2 = &e;
  31 +
  32 + cptr1->a = 1;
  33 + cptr2->a = 2;
  34 +
  35 +}
  36 +
... ...
examples11/01-cast/cast.cpp 0 → 100644
  1 +class Storable {
  2 +public:
  3 +virtual ~Storable(){};
  4 +};
  5 +
  6 +class Component : public virtual Storable
  7 +{ /* ... */ };
  8 +class Receiver : public Component
  9 +{ /* ... */ };
  10 +class Transmitter : public Component
  11 +{ /* ... */ };
  12 +class Radio : public Receiver, public Transmitter
  13 +{ /* ... */ };
  14 +
  15 +int main()
  16 +{
  17 + Radio r;
  18 +
  19 + Storable* s = &r;
  20 +
  21 + Transmitter* t = dynamic_cast<Transmitter*> (&r);
  22 +
  23 + Component* c = t;
  24 +
  25 + Radio* rptr = dynamic_cast<Radio*>(c);
  26 +
  27 +}
... ...
examples11/01-cast/makefile 0 → 100644
  1 +all: cast
  2 +
  3 +cast: cast.cpp
  4 + g++ -g -Wall -pedantic $^ -o $@
  5 +
  6 +.PHONY: clean
  7 +
  8 +clean:
  9 + -rm cast
  10 +
... ...
examples11/01-funptr/funptr1.cpp renamed to examples11/02-funptr/funptr1.cpp
examples11/01-funptr/funptr2.cpp renamed to examples11/02-funptr/funptr2.cpp
examples11/01-funptr/makefile renamed to examples11/02-funptr/makefile
examples11/02-new/makefile renamed to examples11/03-new/makefile
examples11/02-new/newhandler.cpp renamed to examples11/03-new/newhandler.cpp
examples11/02-new/placement2.cpp renamed to examples11/03-new/placement2.cpp
examples11/02-new/placementnew.cpp renamed to examples11/03-new/placementnew.cpp
examples11/02-new/placementnew2.cpp renamed to examples11/03-new/placementnew2.cpp