a problem with pointers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rhino
    New Member
    • Nov 2006
    • 4

    #1

    a problem with pointers

    Hello,

    ---------muziek.h-------------------------------------------------

    #include <iostream>
    #include<string >
    #include<vector >
    using namespace std;

    class Muziekbestand
    {
    protected :
    string artiest, naam;
    int duur;
    string bestandsnaam;
    public :
    Muziekbestand() ;
    Muziekbestand(s tring naam);
    void afspelen();
    void printgegevens() ;
    };

    class Muzieklijsten
    {
    protected :
    string naam;
    vector<Muziekbe stand> *lijst;

    public:
    Muzieklijsten() ;
    Muzieklijsten(s tring lijstnaam);
    void voegToe(Muziekb estand *a);
    void verwijder(int a);
    void search();



    };

    -----------------------------Muziekbestand.c pp----------------------------

    #include <iostream>
    #include<string >
    #include<muziek .h>
    using namespace std;

    Muziekbestand:: Muziekbestand()
    {
    artiest="";
    naam= "";
    duur=0;
    bestandsnaam ="";

    };
    Muziekbestand:: Muziekbestand(s tring a)
    {
    artiest="";
    naam="";
    duur=0;
    bestandsnaam =a;
    };
    void Muziekbestand:: afspelen()
    {
    cout << "u speelt nu " << naam << " van " << artiest << " met duur " << " en path " << bestandsnaam << endl;

    };
    void Muziekbestand:: printgegevens()
    {
    cout <<"artiest: " << artiest << endl;
    cout <<"naam: " << naam << endl;
    cout <<"tijdsduur: " << duur << endl;
    cout <<"path: " << bestandsnaam << endl;
    };

    --------------------------Muzieklijsten.c pp--------------------------------

    #include <iostream>
    #include<string >
    #include<muziek .h>
    #include <vector>
    using namespace std;

    Muzieklijsten:: Muzieklijsten()
    {
    naam ="alle muziek" ;
    }
    Muzieklijsten:: Muzieklijsten(s tring a)
    {
    naam=a;
    }
    void Muzieklijsten:: voegToe(Muziekb estand *a)
    {
    lijst.push_back (a);
    }
    void Muzieklijsten:: verwijder(int a)
    {
    lijst.erase(a);
    }
    void search()
    {
    cout << "geef een zoekwaarde in " << endl;
    char ch;
    cin >> ch;

    };
    ------------------------------------------------------------------------
    the problem here :
    I have a class Muzieklijsten(M uziekbestand *a)
    As far As I know it means : I will make a class Muzieklijsten and I will use a pointer to 'Muziekbestande n'

    In mij class I want to add this pointer to a vector. but here I get the following error:

    muzieklijsten.c pp:17: error: request for member `push_back' in `
    this->Muzieklijsten: :lijst', which is of non-aggregate type `
    std::vector<Muz iekbestand, std::allocator< Muziekbestand> >*'
    muzieklijsten.c pp: In member function `void Muzieklijsten:: verwijder(int)' :


    I have no clue what the problem is here.

    I hope some one can solve this
    thanks
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    I think your vector
    Code:
     vector<Muziekbestand> *lijst;
    should be
    Code:
    vector<Muziekbestand *> lijst;
    you then have a problem with
    Code:
    void Muzieklijsten::verwijder(int a)
    {
    lijst.erase(a);
    }
    erase() requires an interator as a parameter you are passing it an int

    Comment

    Working...