Resolution Order-Object Oriented Programming-Lecture Slides, Slides of Object Oriented Programming

Main topics in this course are object-orientation, objects and classes, overloading, inheritance, polymorphism, generic programming, exception handling, introduction to design patterns. This lecture includes: Resolution, Order, Object, Orient, Program, Compiler, Specialization, Template, Void, Sort, Vector, Char, Overload

Typology: Slides

2011/2012

Uploaded on 08/08/2012

anchita
anchita 🇮🇳

4.4

(7)

113 documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Object
Object-
-Oriented Programming
Oriented Programming
(OOP)
(OOP)
Lecture No. 37
Lecture No. 37
Resolution Order
Resolution Order
template< typename T >
template< typename T >
class Vector {
class Vector {
};
};
template< typename T >
template< typename T >
class Vector< T* > {
class Vector< T* > {
};
};
template< >
template< >
class Vector< char* > {
class Vector< char* > {
};
};
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Resolution Order-Object Oriented Programming-Lecture Slides and more Slides Object Oriented Programming in PDF only on Docsity!

Object

Object

Oriented Programming

Oriented Programming

(OOP)

(OOP)

Lecture No. 37

Lecture No. 37

Resolution Order

Resolution Order

► ► Compiler searches a complete specializationCompiler searches a complete specialization

whose type matches exactly with that of whose type matches exactly with that of

declaration

declaration

If it fails then it searches for some partial

If it fails then it searches for some partial

specialization

specialization

► ► In the end it searches for some generalIn the end it searches for some general

template template

Example

Example

Resolution Order

Resolution Order

int main() { int main() {

char* str = char* str = ““Hello World!Hello World!””;;

sort(str); // sort( char* )

sort(str); // sort( char* )

Vector<char*> v1 = {

Vector<char*> v1 = { “

ab

ab ”

cd

cd ”

sort(v1); //sort( Vector<char> & ) sort(v1); //sort( Vector<char> & )

Templates and Inheritance

Templates and Inheritance

We can use inheritance comfortably with

We can use inheritance comfortably with

templates or their specializations

templates or their specializations

But we must follow one rule:

But we must follow one rule:

Derived class must take at least as many

Derived class must take at least as many

template parameters as the base class

template parameters as the base class

requires for an instantiationrequires for an instantiation””

Derivations of a Template

Derivations of a Template

int main() { int main() {

A< int > obj1; A< int > obj1;

B< int* > obj2;

B< int* > obj2;

return 0;

return 0;

Derivations of a Partial Sp.

Derivations of a Partial Sp.

► ► A class template may inherit from a partialA class template may inherit from a partial

specialization specialization

template< class T > template< class T >

class A

class A

template< class T > template< class T >

class A< T* >

class A< T* >

docsity.com

Derivations of a Partial Sp.

Derivations of a Partial Sp.

► ► Complete specialization or ordinary classComplete specialization or ordinary class

cannot inherit from a partial specialization cannot inherit from a partial specialization

template< > template< >

class B< int* > : public A< T* >

class B< int* > : public A< T* >

{ { …… }} // Error: Undefined// Error: Undefined ‘‘TT’’

class B : public A< T* > class B : public A< T* >

// Error

// Error : Undefined

: Undefined ‘

T

T

Derivations of a Complete Sp.

Derivations of a Complete Sp.

template< class T >

template< class T >

class B : public A< float* > class B : public A< float* >

int main() {

int main() {

A< float* > obj1;

A< float* > obj1;

B< int > obj2; B< int > obj2;

return 0; return 0;

Derivations of a Complete Sp.

Derivations of a Complete Sp.

int main() { int main() {

A< float* > obj1; A< float* > obj1;

B< double* > obj2;

B< double* > obj2;

return 0;

return 0;

Derivations of a Complete Sp.

Derivations of a Complete Sp.

int main() { int main() {

A< float* > obj1; A< float* > obj1;

B obj2;

B obj2;

return 0;

return 0;

Derivations of Ordinary Class

Derivations of Ordinary Class

int main() { int main() {

A obj1; A obj1;

B< int* > obj2;

B< int* > obj2;

return 0;

return 0;

Derivations of Ordinary Class

Derivations of Ordinary Class

int main() { int main() {

A obj1; A obj1;

B< char* > obj2;

B< char* > obj2;

return 0;

return 0;