Computer Notes - Resolution Order - PowerPoint PPT Presentation

View by Category
About This Presentation
Title:

Computer Notes - Resolution Order

Description:

- Computer Notes - Resolution Order in Object oriented Programming what is Resolution Order Explain about it in detail .explain it with example – PowerPoint PPT presentation

Number of Views:154

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Computer Notes - Resolution Order


1
Resolution Order
http//ecomputernotes.com
2
Resolution Order
  • templatelt typename T gt
  • class Vector
  • templatelt typename T gt
  • class Vectorlt T gt
  • templatelt gt
  • class Vectorlt char gt

http//ecomputernotes.com
3
Resolution Order
  • Compiler searches a complete specialization whose
    type matches exactly with that of declaration
  • If it fails then it searches for some partial
    specialization
  • In the end it searches for some general template

http//ecomputernotes.com
4
Example Resolution Order
  • int main()
  • Vectorlt char gt strVector
  • // Vectorlt char gt instantiated
  • Vectorlt int gt iPtrVector
  • // Vectorlt T gt instantiated
  • Vectorlt int gt intVector
  • // Vectorlt T gt instantiated
  • return 0

http//ecomputernotes.com
5
Function Template Overloading
  • templatelt typename T gt
  • void sort( T )
  • templatelt typename T gt
  • void sort( Vectorlt T gt )
  • templatelt gt
  • void sortlt Vectorltchargt gt(
  • Vectorlt char gt )
  • void sort( char )

http//ecomputernotes.com
6
Resolution Order
  • Compiler searches target of a function call in
    the following order
  • Ordinary Function
  • Complete Specialization
  • Partial Specialization
  • Generic Template

http//ecomputernotes.com
7
Example Resolution Order
  • int main()
  • char str Hello World!
  • sort(str) // sort( char )
  • Vectorltchargt v1 ab, cd,
  • sort(v1) //sort( Vectorltchargt )

http//ecomputernotes.com
8
Example Resolution Order
  • Vectorltintgt v2 5, 10, 15, 20
  • sort(v2) // sort( VectorltTgt )
  • int iArray 5, 2, 6 , 70
  • sort(iArray) // sort( T )
  • return 0

http//ecomputernotes.com
9
Templates and Inheritance
  • We can use inheritance comfortably with templates
    or their specializations
  • But we must follow one rule
  • Derived class must take at least as many
    template parameters as the base class requires
    for an instantiation

http//ecomputernotes.com
10
Derivations of a Template
  • A class template may inherit from another class
    template
  • templatelt class T gt
  • class A
  • templatelt class T gt
  • class B public Alt T gt

http//ecomputernotes.com
11
Derivations of a Template
  • int main()
  • Alt int gt obj1
  • Blt int gt obj2
  • return 0

http//ecomputernotes.com
12
Derivations of a Template
  • A partial specialization may inherit from a class
    template
  • templatelt class T gt
  • class Blt T gt public Alt T gt

http//ecomputernotes.com
13
Derivations of a Template
  • int main()
  • Alt int gt obj1
  • Blt int gt obj2
  • return 0

http//ecomputernotes.com
14
Derivations of a Template
  • Complete specialization or ordinary class cannot
    inherit from a class template
  • templatelt gt
  • class Blt char gt public Alt T gt
  • // Error T undefined
  • class B public Alt T gt
  • // Error T undefined

http//ecomputernotes.com
15
Derivations of a Partial Sp.
  • A class template may inherit from a partial
    specialization
  • templatelt class T gt
  • class A
  • templatelt class T gt
  • class Alt T gt

http//ecomputernotes.com
16
Derivations of a Partial Sp.
  • templatelt class T gt
  • class B public Alt T gt
  • int main()
  • Alt int gt obj1
  • Blt int gt obj2
  • return 0

http//ecomputernotes.com
17
Derivations of a Partial Sp.
  • A partial specialization may inherit from a
    partial specialization
  • templatelt class T gt
  • class Blt T gt public Alt T gt

http//ecomputernotes.com
18
Derivations of a Partial Sp.
  • int main()
  • Alt int gt obj1
  • Blt int gt obj2
  • return 0

http//ecomputernotes.com
19
Derivations of a Partial Sp.
  • Complete specialization or ordinary class cannot
    inherit from a partial specialization
  • templatelt gt
  • class Blt int gt public Alt T gt
  • // Error Undefined T
  • class B public Alt T gt
  • // Error Undefined T

http//ecomputernotes.com
20
Derivations of a Complete Sp.
  • A class template may inherit from a complete
    specialization
  • templatelt class T gt class A
  • templatelt gt
  • class Alt float gt

http//ecomputernotes.com
21
Derivations of a Complete Sp.
  • templatelt class T gt
  • class B public Alt float gt
  • int main()
  • Alt float gt obj1
  • Blt int gt obj2
  • return 0

http//ecomputernotes.com
22
Derivations of a Complete Sp.
  • A partial specialization may inherit from a
    complete specialization
  • templatelt class T gt
  • class Blt T gt public Alt float gt

http//ecomputernotes.com
23
Derivations of a Complete Sp.
  • int main()
  • Alt float gt obj1
  • Blt int gt obj2
  • return 0

http//ecomputernotes.com
24
Derivations of a Complete Sp.
  • A complete specialization may inherit from a
    complete specialization
  • templatelt gt
  • class Blt double gt
  • public Alt float gt

http//ecomputernotes.com
25
Derivations of a Complete Sp.
  • int main()
  • Alt float gt obj1
  • Blt double gt obj2
  • return 0

http//ecomputernotes.com
26
Derivations of a Complete Sp.
  • An ordinary class may inherit from a complete
    specialization
  • class B public Alt float gt

http//ecomputernotes.com
27
Derivations of a Complete Sp.
  • int main()
  • Alt float gt obj1
  • B obj2
  • return 0

http//ecomputernotes.com
28
Derivations of Ordinary Class
  • A class template may inherit from an ordinary
    class
  • class A
  • templatelt class T gt
  • class B public A

http//ecomputernotes.com
29
Derivations of Ordinary Class
  • int main()
  • A obj1
  • Blt int gt obj2
  • return 0

http//ecomputernotes.com
30
Derivations of Ordinary Class
  • A partial specialization may inherit from an
    ordinary class
  • templatelt class T gt
  • class Blt T gt public A

http//ecomputernotes.com
31
Derivations of Ordinary Class
  • int main()
  • A obj1
  • Blt int gt obj2
  • return 0

http//ecomputernotes.com
32
Derivations of Ordinary Class
  • A complete specialization may inherit from an
    ordinary class
  • templatelt gt
  • class Blt char gt public A

http//ecomputernotes.com
33
Derivations of Ordinary Class
  • int main()
  • A obj1
  • Blt char gt obj2
  • return 0

http//ecomputernotes.com
About PowerShow.com