Get storage off stack for array
#include <iostream>
using namespace std;
template <class T, int n>
class assign_array {
public:
T a[n];
};
int main()
{
assign_array<double, 50> x, y;
for (int i = 0; i < 50; ++i)
x.a[i] = i;
for (int i = 0; i < 50; ++i)
y.a[i] = i * 2;
for (int i = 0; i < 50; ++i)
cout << x.a[i] << "\t";
for (int i = 0; i < 50; ++i)
cout << y.a[i] << "\t";
x = y; //should work efficiently
for (int i = 0; i < 50; ++i)
cout << x.a[i] << "\t";
}
Related examples in the same category