







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concept of friend functions and templates in object-oriented programming (oop) through a series of rules and examples. Friend functions and templates are used to grant access to the private and protected members of a class to non-member functions and classes. The rules for declaring friend functions and templates, their instantiation, and the implications of different type parameters.
Typology: Slides
1 / 13
This page cannot be seen from the preview
Don't miss anything!








template< class U >void template< class U > void doSomethingdoSomething( U u ) {( U u ) { B< U > ib;ib.data = 78; B< U > ib; ib.data = 78; } }
class B< int > { class B< int > {int data; int data; friend void doSomething( int );friend A< int >; friend void doSomething( int ); friend A< int >; }; }; docsity.com
template< class T >class A { template< class T > class A { void method() { void method() {B< char > cb; B< char > cb; // OK!// OK! cb.data = 8;B< int > ib; cb.data = 8; B< int > ib; } } ib.data = 9;^ ib.data = 9; }; }; docsity.com
template< class T >class B { template< class T > class B { T data;template< class U > T data; template< class U > }; }; friend class A;^ friend class A;
template< class U >void doSomething( U u ) { template< class U > void doSomething( U u ) { B< int > ib;ib.data = 56; B< int > ib; ib.data = 56; // OK// OK } }