Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main
- #include <iostream>
- #include "book.h"
- #include <string>
- int main() {
- book v4;
- book v6;
- book v5;
- v6.SetTitle("Missing You");
- v6.SetAuthor("Missin you so much my baby");
- v5.SetTitle(move(v6.GetTitle()));
- cout << v5 << endl;
- cout << v6 << endl;
- v4 = v6;
- cout << v4 << endl;
- system("pause");
- return 0;
- }
- .cpp
- #include "book.h"
- #include <iostream>
- #include <iomanip>
- #include <functional>
- using namespace std;
- book::book()
- {
- cout << "Konstruktor bez parametru" << endl;
- }
- book::book(string&& author, string&& title)
- :author(author), title(title)
- {
- cout << "Konstruktor z r-referencją" << endl;
- }
- book::book(const string& author, const string& title)
- : author(author), title(title)
- {
- cout << "Konstruktor z l-referencją" << endl;
- }
- string book::GetAuthor()const
- {
- return this->author;
- }
- string book::GetTitle()const
- {
- return this->title;
- }
- void book::SetAuthor(const string& author)
- {
- this->author = author;
- }
- void book::SetAuthor(string&& author)
- {
- this->author = author;
- }
- void book::SetTitle(const string& title)
- {
- this->title = title;
- }
- void book::SetTitle(string&& title)
- {
- this->title = title;
- }
- book::book(const book& other)
- :author(other.author), title(other.title)
- {
- cout << "kopiowanie" << endl;
- author = other.author;
- title = other.title;
- }
- book::book(book&& other)
- : author(other.author), title(other.title)
- {
- cout << "Przenoszenie konstruktora z r-referencją" << endl;
- author = other.author;
- title = other.title;
- other.author = nullptr;
- other.title = nullptr;
- }
- book& book::operator=(const book& right) {
- cout << "Operator przypisania z l-referencją" << endl;
- book tmp = right;
- swap(author, tmp.author);
- swap(title, tmp.title);
- return *this;
- }
- book& book::operator=(book&& right) {
- cout << "Prenoszący operator przypisania z r-referencją" << endl;
- swap(author, right.author);
- swap(title, right.title);
- cout << "Prenoszący operator przypisania z r-referencją" << endl;
- return *this;
- }
- ostream& operator<<(ostream& stream, const book& book)
- {
- stream << "Author : ";
- stream.fill(' ');
- stream << book.author;
- stream << setw(15);
- stream.fill(' ');
- stream << "Title : ";
- stream.fill(' ');
- stream << book.title;
- stream.fill(' ');
- stream << endl;
- return stream;
- }
- book::~book()
- {
- cout << "Destruktor " << endl;
- }
- .h
- #pragma once
- #include <string>
- #include <iostream>
- using namespace std;
- class book
- {
- private:
- string author;
- string title;
- public:
- book();
- book(string&& author, string&& title);
- book(const string& author, const string& title);
- string GetAuthor() const;
- string GetTitle() const;
- void SetAuthor(const string& author);
- void SetAuthor(string&& author);
- void SetTitle(const string& title);
- void SetTitle(string&& title);
- book(const book& other);
- book(book&& other);
- book& operator=(const book& right);
- book& operator=(book&& right);
- friend std::ostream& operator<<(std::ostream &stream, const book& book);
- ~book();
- };
- #pragma once
- #include "book.h"
- #include <initializer_list>
- class Library {
- /* ...................... */
- public:
- Library();
- Library(std::initializer_list<book> list);
- Library(const Library& orig);
- Library(Library&& orig);
- Library& operator=(const Library& ritght);
- Library& operator=(Library&& ritght);
- book& operator[](std::size_t index);
- const book& operator[](std::size_t index) const;
- std::size_t GetSize() const;
- ~Library();
- Library(std::initializer_list<double> initList)
- : size{ initList.size() }, array{new double[initList.size()]}
- {
- std::size_t i = 0;
- for (double v : initList)
- {
- array[i] = v;
- i++;
- }
- }
- size_t GetSize() const {
- return size;
- }
- ~Library()
- {
- if (array != nullptr)
- delete[] array;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement