Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
TempSpecial2
//g++ 7.4.0 //TempSpecial2:example of specialization of a template and its member template where specialized Name and Ad classes with std::string type prints a message for a function that returns address; this code is created by Rezaul Hoque on May 12,2022; //contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> #include <string> template <class X> class Name { X n; public: Name(){} Name(X); Name(Name&); ~Name(){} X getName(); template <class V>//member template class Ad{ V ad; public: Ad(){} Ad(V); ~Ad(){} V getAd(){ return ad;} }; }; template<>//for the specialized Name template <>//for the specialized Ad std::string Name<std::string>::Ad<std::string>::getAd(){std::cout<<"Address of a specialized template.\n"; return ad;} //definition of Name(X) constructor declared earlier template<class X> Name<X>::Name(X a){n=a;} //definition of Name (Name&) copy constructor declared earlier template<class X> Name<X>::Name(Name& c){n=c.n;} //definition of getName() function declared earlier template<class X> X Name<X>::getName(){ return n;} //definition of Ad(V) constructor declared earlier template <class X> template <class V> Name<X>::Ad<V>::Ad(V a){ad=a;} int main() { Name<std::string> naam("AAA"); Name<std::string>::Ad<std::string> bari("Nowhere "); std::cout<<naam.getName()<<" \n"; std::cout<<bari.getAd(); return 0; }
run
|
edit
|
history
|
help
0
HalumResto
FAK MEN
Amisha
Trapping rain water problem
Roger Cheng
queue-with-fixed-size
single_digit
FindMissingNewt
Stream2
sd5