This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
|
cpp:class_templates [2019/05/04 04:32] gthanos [Ένα πιο σύνθετο παράδειγμα] |
cpp:class_templates [2019/05/14 10:08] gthanos [Templates κλάσεων] |
||
|---|---|---|---|
| Line 4: | Line 4: | ||
| <code cpp Box.hpp> | <code cpp Box.hpp> | ||
| + | #ifndef _BOX_HPP_ | ||
| + | #define _BOX_HPP_ | ||
| + | |||
| template < | template < | ||
| class Box { | class Box { | ||
| Line 31: | Line 34: | ||
| return out; | return out; | ||
| } | } | ||
| + | #endif | ||
| </ | </ | ||
| Line 62: | Line 66: | ||
| <code cpp Array.hpp> | <code cpp Array.hpp> | ||
| - | |||
| #ifndef __ARRAY_H__ | #ifndef __ARRAY_H__ | ||
| #define __ARRAY_H__ | #define __ARRAY_H__ | ||
| Line 139: | Line 142: | ||
| std:: | std:: | ||
| for(int i=0; i<size; i++) { | for(int i=0; i<size; i++) { | ||
| - | out << t.array[i] << " "; | + | out << t.array[i] |
| + | if(i< | ||
| + | out << ", "; | ||
| } | } | ||
| return out; | return out; | ||
| Line 147: | Line 152: | ||
| <code cpp ArrayUsage.cpp> | <code cpp ArrayUsage.cpp> | ||
| - | |||
| #include " | #include " | ||
| + | #include " | ||
| #define ARRAY_SIZE 10 | #define ARRAY_SIZE 10 | ||
| Line 160: | Line 165: | ||
| | | ||
| cout << a << endl; | cout << a << endl; | ||
| - | | ||
| Array< | Array< | ||
| + | cout << b << endl; | ||
| + | | ||
| + | Array< | ||
| + | sts[0] = Student(" | ||
| + | sts[1] = Student(" | ||
| + | sts[2] = Student(" | ||
| + | | ||
| + | cout << sts << endl; | ||
| | | ||
| } | } | ||
| </ | </ | ||