User Tools

Site Tools


cpp:class_templates

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
cpp:class_templates [2019/05/03 15:04] gthanoscpp:class_templates [2019/05/04 04:25] – [Templates κλάσεων] gthanos
Line 33: Line 33:
 </code> </code>
  
-H παραπάνω κλάση μπορεί να παράγει διαφορετικούς τύπους δεδομένων, ανάλογα με τον τύπο **T**. Στο παρακάτω παράδειγμα έχουμε ένα μία κλάση **Box<int>**, μία κλάση **Box<double>** και μία κλάση **Box<Student*>**.+H παραπάνω κλάση μπορεί να παράγει διαφορετικούς τύπους δεδομένων, ανάλογα με τον τύπο **T**. Στο παρακάτω παράδειγμα έχουμε ένα μία κλάση **Box<int>**, μία κλάση **Box<double>** και μία κλάση **Box<Student>**.
  
 <code cpp BoxUsage.cpp> <code cpp BoxUsage.cpp>
Line 46: Line 46:
   Box<int> b(15);   Box<int> b(15);
   Box<double> d(4.23);   Box<double> d(4.23);
-  Student george = {"George", 1234}; +  Student kate = {"Kate", 1234}; 
-  Box<Student*> studentBox(&george);+  Box<Student> studentBox(kate)
 +  Student katherine = studentBox.get(); 
 +  katherine.setName("Katherine"); 
 +   
 +  cout << kate << endl; 
 +  cout << katherine << endl; 
 +  cout << studentBox.get() << endl;
 } }
 </code> </code>
cpp/class_templates.txt · Last modified: 2020/05/25 06:52 (external edit)