Compare commits
2 Commits
c49545d3ff
...
e5bcc44b2e
Author | SHA1 | Date | |
---|---|---|---|
|
e5bcc44b2e | ||
|
cc70b96d30 |
@ -24,7 +24,7 @@ class Array
|
|||||||
|
|
||||||
Array(const Array& src)
|
Array(const Array& src)
|
||||||
{
|
{
|
||||||
new T[0];
|
this->_arr = new T[0];
|
||||||
*this = src;
|
*this = src;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -42,6 +42,7 @@ class Array
|
|||||||
new T[src._size];
|
new T[src._size];
|
||||||
for (size_t i = 0; i < src._size; i++)
|
for (size_t i = 0; i < src._size; i++)
|
||||||
this->_arr[i] = src._arr[i];
|
this->_arr[i] = src._arr[i];
|
||||||
|
return *this;
|
||||||
};
|
};
|
||||||
|
|
||||||
T& operator[](unsigned int index) const
|
T& operator[](unsigned int index) const
|
||||||
|
@ -24,14 +24,39 @@ int main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Fill and get";
|
std::cout << "Fill and get" << std::endl;
|
||||||
{
|
{
|
||||||
unsigned int size = 10;
|
unsigned int size = 10;
|
||||||
Array<int> t(size);
|
Array<int> t(size);
|
||||||
for (unsigned int i = 0; i != size; i++)
|
for (unsigned int i = 0; i != size; i++)
|
||||||
t[i] = i;
|
t[i] = i;
|
||||||
for (unsigned int i = 0; i != size; i++)
|
for (unsigned int i = 0; i != size; i++)
|
||||||
std::cout << i << std::endl;
|
std::cout << t[i] << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << "Copy and get" << std::endl;
|
||||||
|
{
|
||||||
|
unsigned int size = 10;
|
||||||
|
Array<int> t(size);
|
||||||
|
for (unsigned int i = 0; i != size; i++)
|
||||||
|
t[i] = i;
|
||||||
|
Array<int> b(t);
|
||||||
|
for (unsigned int i = 0; i != size; i++)
|
||||||
|
std::cout << b[i] << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << "operator = and get" << std::endl;
|
||||||
|
{
|
||||||
|
unsigned int size = 10;
|
||||||
|
Array<int> t(size);
|
||||||
|
for (unsigned int i = 0; i != size; i++)
|
||||||
|
t[i] = i;
|
||||||
|
Array<int> b;
|
||||||
|
b = t;
|
||||||
|
for (unsigned int i = 0; i != size; i++)
|
||||||
|
std::cout << b[i] << std::endl;
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user