diff --git a/td/td1/include/vector.h b/td/td1/include/vector.h index 0710a1e..3694358 100644 --- a/td/td1/include/vector.h +++ b/td/td1/include/vector.h @@ -21,6 +21,7 @@ public: friend std::istream& operator>>(std::istream& stream, Vector& vec); Vector& operator=(const Vector& other); + Vector& operator()(const Vector& other); private: size_t _capacity; @@ -86,6 +87,13 @@ Vector& Vector::operator=(const Vector& other) return *this; } +template +Vector& Vector::operator()(const Vector& other) +{ + *this = other; + return *this; +} + template size_t Vector::Capacity() { return _capacity; } template diff --git a/td/td1/src/main.cpp b/td/td1/src/main.cpp index c533303..a881be5 100644 --- a/td/td1/src/main.cpp +++ b/td/td1/src/main.cpp @@ -11,17 +11,18 @@ int main(void) Vector floatVector(10,1.2); std::cout << "Float vector: " << floatVector << std::endl; - Vector charVector(5); - std::cout << "Capacity of charVector:" << charVector.Capacity() << "\t Size of charVector: " << charVector.Size() << std::endl; - std::cin >> charVector; - std::cout << "char vector: " << charVector << std::endl; + auto charVector = new Vector(5); + std::cout << "Capacity of charVector:" << charVector->Capacity() << "\t Size of charVector: " << charVector->Size() << std::endl; + std::cin >> *charVector; + std::cout << "char vector: " << *charVector << std::endl; - Vector anotherVector = charVector; - std::cout << "char vector: " << charVector << std::endl; + Vector anotherVector = *charVector; + std::cout << "char vector: " << anotherVector << std::endl; + delete charVector; Vector copiedVector; - copiedVector = anotherVector; - std::cout << "char vector: " << charVector << std::endl; + copiedVector(anotherVector); + std::cout << "char vector: " << copiedVector << std::endl; return 0; }