/docs/MyDocs

To get this branch, use:
bzr branch http://darksoft.org/webbzr/docs/MyDocs

« back to all changes in this revision

Viewing changes to Development/languages/C/Core/class/inheritance.txt

  • Committer: Suren A. Chilingaryan
  • Date: 2009-04-09 03:21:08 UTC
  • Revision ID: csa@dside.dyndns.org-20090409032108-w4edamdh4adrgdu3
import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
1. ������������
 
2
    class L
 
3
    class A: public L                            /->A->L
 
4
    class B: public L                           C-->B->L
 
5
    class C: public A, public B
 
6
                                    ������� ��� ������� L, ������������:
 
7
                                    A::L::method, B::L::method
 
8
    
 
9
    class A: virtual public L                    /->A-\
 
10
    class B: virtual public L                   C-->B->L
 
11
                                    ������� ���� ������ L
 
12
    
 
13
    �������� ����������� �������������:
 
14
     /->A-\
 
15
    C-->B->L
 
16
     \->D->L
 
17
 
 
18
2. Private inheritance can be used to eleminate ambiguity in such case, for
 
19
  example:
 
20
            B: A ;  C: A ; D: public B, private C
 
21
    When accessing baseclass A from external classes, acess will go in the 
 
22
    way "D::B::A" automatically.
 
23
        
 
24
3. � ��� ����� ������ ����� ����� "using A::f" ( �� ������������� �� ����������,
 
25
  �� ����� ����� ���������� �������� ����� �����-��������� c.C::f()
 
26
 
 
27
4. ������
 
28
    class B { f(int) }
 
29
    class D: B { f(char*} }
 
30
    D *pd->f(1)                 - ���� ��� ������, � �� ���������
 
31
                                ���� pd->B::f(1)
 
32
 
 
33
5. �� ������������ ���������� �� ������������� ������, � ������ ����� ������.
 
34
    class A{}; class B : A {}; class C : B{}; c = new C;
 
35
 For example, if the constructor for "B" calls a virtual function,  it will 
 
36
 invoke a version defined for "B" or "A" , but not one from "C". At that point 
 
37
 of construction, the object isnt yet a "C" ; it is merely a partially 
 
38
 constructed object. It is best to avoid calling virtual functions during 
 
39
 construction and destruction.
 
40
 
 
41
6. If the delete constroctur is overrided in the base class, the destructor (at
 
42
 least abstract one) should be declared as well. Otherwise, the invalid size 
 
43
 would be passed to delete(void*, size_t) operator.