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);
|
||||
|
||||
Vector<T>& operator=(const Vector<T>& other);
|
||||
Vector<T>& operator()(const Vector<T>& other);
|
||||
|
||||
private:
|
||||
size_t _capacity;
|
||||
|
@ -86,6 +87,13 @@ Vector<T>& Vector<T>::operator=(const Vector<T>& other)
|
|||
return *this;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Vector<T>& Vector<T>::operator()(const Vector<T>& other)
|
||||
{
|
||||
*this = other;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
size_t Vector<T>::Capacity() { return _capacity; }
|
||||
template <class T>
|
||||
|
|
|
@ -11,17 +11,18 @@ int main(void)
|
|||
Vector<float> floatVector(10,1.2);
|
||||
std::cout << "Float vector: " << floatVector << std::endl;
|
||||
|
||||
Vector<char> 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<char>(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<char> anotherVector = charVector;
|
||||
std::cout << "char vector: " << charVector << std::endl;
|
||||
Vector<char> anotherVector = *charVector;
|
||||
std::cout << "char vector: " << anotherVector << std::endl;
|
||||
delete charVector;
|
||||
|
||||
Vector<char> copiedVector;
|
||||
copiedVector = anotherVector;
|
||||
std::cout << "char vector: " << charVector << std::endl;
|
||||
copiedVector(anotherVector);
|
||||
std::cout << "char vector: " << copiedVector << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue