1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
template <class P>
class Print_Elements
{
public:
Print_Elements(P _num)
{
cout << _num << ' ';
}
};
template <class T>
class Multiply
{
private:
T _num;
public:
Multiply<T> (T& _num)
{
return _num * _num; // Error in this class (maybe) here
}
};
template <class C>
class Upper_Case
{
private:
C _char;
public:
Upper_Case<C> (C& _char)
{
_char = _char + 'A' - 'a';
return (_char); // Error in this class (maybe) here
}
};
int main()
{
deque<int> deque_int;
deque<long> deque_long;
deque<char> deque_char;
for (int i = 1; i <= 9; i++)
deque_int.push_front(i);
for (long j = 1000000000; j <= 1000000009; j++)
deque_long.push_back(j);
for (char k = 'a'; k <= 'i'; k++)
{
deque_char.push_front(k);
deque_char.push_back(k);
}
cout << "Elements at the beginning:";
cout << endl;
cout << " Deque<Int>: ";
for_each(deque_int.begin(), deque_int.end(), Print_Elements()); // Error here
cout << endl;
cout << " Deque<Long>: ";
for_each(deque_long.begin(), deque_long.end(), Print_Elements()); // Error here
cout << endl;
cout << " Deque<Char>: ";
for_each(deque_char.begin(), deque_char.end(), Print_Elements()); // Error here
transform(deque_int.begin(), deque_int.end(), Multiply<int>()); // Error here
transform(deque_long.begin(), deque_long.end(), Multiply<long>()); // Error here
transform(deque_char.begin(), deque_char.end(), Upper_Case<char>()); // Error here
cout << "Elements after transform:";
cout << endl;
cout << " Deque<Int>: ";
for_each(deque_int.begin(), deque_int.end(), Print_Elements()); // Error here
cout << endl;
cout << " Deque<Long>: ";
for_each(deque_long.begin(), deque_long.end(), Print_Elements()); // Error here
cout << endl;
cout << " Deque<Char>: ";
for_each(deque_char.begin(), deque_char.end(), Print_Elements()); // Error here
return 0;
}
| |