Vektoren in Klassen



  • Hiho!

    Ich habe ne Klasse Library, in der ich Elemente einer anderen Klasse verwalte(Buch und Mitglied). Ich habe 2 Vektoren, die als private deklariert sind. (so stehts auch in der aufgabe)
    Wie schaffe ich das, dass ich zum Beispiel an eine Funktion ein Buch übergebe

    void add_book(Book a){
    	vbook.push_back(a);
    }
    

    und dieses dann in den Vektor rein bringe?

    Hier die Klasse:

    #include "Book.h"
    #include "Patron.h"
    #include <vector>
    
    class Bibliothek
    {
    private:
    	struct Transaction{
    		Book book;
    		Patron patron;
    	};
    	std::vector<Book>vbook;
    	std::vector<Patron>vpatron;
    	std::vector<Transaction>vtransaction;
    public:
    	Bibliothek();
    	~Bibliothek();
    	void add_book(Book& a);
    	void add_patron(Patron& a);
    	void borrow_book(Book& a);
    	bool check_payment(Patron& a);
    	bool check_register(Patron& a);
    };
    

    Danke im Vorraus 🙂



  • So wie in der von dir gezeigten add_book Funktion.


Anmelden zum Antworten