Code:
#include <stdio.h>
class var_array
{
private:
int *data;
const int size;
var_array(const var_array &other); //Konstruktor za kopiranje se ne moze koristiti
public:
var_array(const int _size):
size(_size)
{
data = new int(size);
}
~var_array()
{
delete []data;
}
int &operator[](const unsigned index)
{
return (data[index]);
}
};
void store_it(var_array &test_array)
{
test_array[1] = 1;
test_array[3] = 3;
printf("Odradio copy\n");
}
int main()
{
var_array test_array(30);
store_it(test_array);
store_it(test_array);
for (int i = 0; i < 30; ++i)
{
printf("%d\n",test_array[i]);
}
printf("gotovo\n");
return 0;
}
#include <stdio.h>
class var_array
{
private:
int *data;
const int size;
var_array(const var_array &other); //Konstruktor za kopiranje se ne moze koristiti
public:
var_array(const int _size):
size(_size)
{
data = new int(size);
}
~var_array()
{
delete []data;
}
int &operator[](const unsigned index)
{
return (data[index]);
}
};
void store_it(var_array &test_array)
{
test_array[1] = 1;
test_array[3] = 3;
printf("Odradio copy\n");
}
int main()
{
var_array test_array(30);
store_it(test_array);
store_it(test_array);
for (int i = 0; i < 30; ++i)
{
printf("%d\n",test_array[i]);
}
printf("gotovo\n");
return 0;
}
The earth teaches us more about ourselves than all the books. Because it resists us. Man discovers himself when he measures himself against the obstacle.