template extending : template class « Class « C++

C++
1. Bitset
2. Class
3. Console
4. Data Structure
5. Data Type
6. Deque
7. Development
8. File
9. Function
10. Generic
11. Language
12. List
13. Map Multimap
14. Overload
15. Pointer
16. Queue Stack
17. Set Multiset
18. STL Algorithms Binary search
19. STL Algorithms Heap
20. STL Algorithms Helper
21. STL Algorithms Iterator
22. STL Algorithms Merge
23. STL Algorithms Min Max
24. STL Algorithms Modifying sequence operations
25. STL Algorithms Non modifying sequence operations
26. STL Algorithms Sorting
27. STL Basics
28. String
29. Valarray
30. Vector
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C++ » Class » template classScreenshots 
template extending
  
template <typename T>
class SimpleTemplate
{
 public:
  SimpleTemplate(T &inObject);

  const T& get();
  void set(T& inObject);

 protected:
  T& mObject;
};

template <typename T>
SimpleTemplate<T>::SimpleTemplate(T &inObject: mObject(inObject)
{
}

template <typename T>
const T& SimpleTemplate<T>::get()
{
  return mObject;
}

template <typename T>
void SimpleTemplate<T>::set(T& inObject)
{
  mObject = inObject;
}

#include <iostream>
#include <string>

using namespace std;

int main(int argc, char** argv)
{
  int i = 7;
  SimpleTemplate<int> intWrapper(i);
  i = 2;
  cout << "wrapper value is " << intWrapper.get() << endl;

  string str = "test";
  SimpleTemplate<string> stringWrapper(str);
  str += "!";
  cout << "wrapper value is " << stringWrapper.get() << endl;
}
  
    
  
Related examples in the same category
1. template class with type parameter
2. template class with generic parameter
3. Demonstrate a very simple safe pointer class.
4. A generic safe-array class that prevents array boundary errors.
5. Get storage off stack for array
6. sequence template
7. Template Version of Generic binary sorted Tree.
8. template class with two generic parameters
9. generic stack template class
10. Using exceptions with templates.
11. Passing by reference and using virtual functions in exceptions.
12. Using Non-Type Arguments with Generic Classes
13. Using Default Arguments with Template Classes
14. Generic Classes: demonstrates a generic stack.
15. An Example with Two Generic Data Types
16. Applying Template Classes: A Generic Array Class
17. Explicit Class Specializations for generic template class
w___ww___._ja_v__a__2___s___._c_o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.