Added operator (). Checking with a pointer if the copy is successful.
This commit is contained in:
parent
596ba25cc0
commit
5d317bedfa
2 changed files with 17 additions and 8 deletions
|
@ -21,6 +21,7 @@ public:
|
||||||
friend std::istream& operator>>(std::istream& stream, Vector<Tfriend>& vec);
|
friend std::istream& operator>>(std::istream& stream, Vector<Tfriend>& vec);
|
||||||
|
|
||||||
Vector<T>& operator=(const Vector<T>& other);
|
Vector<T>& operator=(const Vector<T>& other);
|
||||||
|
Vector<T>& operator()(const Vector<T>& other);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t _capacity;
|
size_t _capacity;
|
||||||
|
@ -86,6 +87,13 @@ Vector<T>& Vector<T>::operator=(const Vector<T>& other)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
Vector<T>& Vector<T>::operator()(const Vector<T>& other)
|
||||||
|
{
|
||||||
|
*this = other;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
size_t Vector<T>::Capacity() { return _capacity; }
|
size_t Vector<T>::Capacity() { return _capacity; }
|
||||||
template <class T>
|
template <class T>
|
||||||
|
|
|
@ -11,17 +11,18 @@ int main(void)
|
||||||
Vector<float> floatVector(10,1.2);
|
Vector<float> floatVector(10,1.2);
|
||||||
std::cout << "Float vector: " << floatVector << std::endl;
|
std::cout << "Float vector: " << floatVector << std::endl;
|
||||||
|
|
||||||
Vector<char> charVector(5);
|
auto charVector = new Vector<char>(5);
|
||||||
std::cout << "Capacity of charVector:" << charVector.Capacity() << "\t Size of charVector: " << charVector.Size() << std::endl;
|
std::cout << "Capacity of charVector:" << charVector->Capacity() << "\t Size of charVector: " << charVector->Size() << std::endl;
|
||||||
std::cin >> charVector;
|
std::cin >> *charVector;
|
||||||
std::cout << "char vector: " << charVector << std::endl;
|
std::cout << "char vector: " << *charVector << std::endl;
|
||||||
|
|
||||||
Vector<char> anotherVector = charVector;
|
Vector<char> anotherVector = *charVector;
|
||||||
std::cout << "char vector: " << charVector << std::endl;
|
std::cout << "char vector: " << anotherVector << std::endl;
|
||||||
|
delete charVector;
|
||||||
|
|
||||||
Vector<char> copiedVector;
|
Vector<char> copiedVector;
|
||||||
copiedVector = anotherVector;
|
copiedVector(anotherVector);
|
||||||
std::cout << "char vector: " << charVector << std::endl;
|
std::cout << "char vector: " << copiedVector << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue