Results 1 to 2 of 2

Thread: pointers help

  1. #1
    Join Date
    Jan 2005
    Beans
    128

    pointers help

    right, so im using c++ and the guichan gui library (its pretty nice ) and tinyXML (which is also very good).

    Right now my problem,

    when for example you define a widget of button type in guichan it is gcn::Button* button, now i have a vector of these and wish to pass the vector by reference into the function:

    the function prototype looks like:

    Code:
    function (vector <gcn::Button*>* buttons);
    now, in that function i can access buttons->size() perfectly well, however when i try and access a specific member of the vector and its members i get an error saying that the member doesn't contain a member function of the name im trying to call (when it does).

    hopw this is all making sense, ive just got myself in a bit of a muddle as if been chopping and changing things trying to make it work and have managed to confuse myself even more in the process.

    thanks in advanced,

    scott

  2. #2
    Join Date
    Mar 2005
    Location
    Dunedin, NZ
    Beans
    559
    Distro
    Kubuntu 7.10 Gutsy Gibbon

    Re: pointers help

    My first observation is that you shouldn't be storing raw pointers in a vector. Use a shared pointer instead.

    Secondly, passing a vector in by reference can be done with the &.

    Code:
    function(vector<gcn::Button*>& buttons)
    Now if you still want to do it your way, and a gcn::Button has a method getName, you can access it by

    Code:
    for (std::size_t i = 0, max = buttons->size(); ++i; i < max)
    {
       sometype name = (*buttons)[i]->getName();
       // ...
    }
    ACCU - for programmers who care

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •