Nested Vector Nester Classes are Nested in my Brain

Discussion in 'C++' started by Chad E. Dollins, Nov 8, 2005.

  1. Hello someone said that I should check this forum out for help to my c++
    problems.

    I will admit at this point I may have really ran myself into the ground
    with this code that I am writing, but I'm hoping for a little help from
    you guys.

    I have a class that needs use of a bread-first search of a quareney tree.
    In this class I have a nested class that should be the implementation of a
    tree that contains two nested classes of its own. Those two classes are a
    Position representation of cartestian coordinate with accessors and
    modifiers and comparison methods. The other inner class is a treenode
    class. This class holds several things, first of all a * to a vector of
    TreeNode * that represent children nodes, A Position as its Payload, A *
    to the parent TreeNode, and * pointer to a Maze object no mentioned above.

    So, my problem is that as I iterate over my children vector I would like
    to access the payload members accessors of the current treenode in the
    vector. Except I get this instead:
    error: request for member `payload' in `
    *(&p1)->__gnu_cxx::__normal_iterator<_Iterator, _Container>::eek:perator->
    [with _Iterator = cs371p::prog::robowars4::Robot::Tree::TreeNode**,
    _Container =
    std::vector<cs371p::prog::robowars4::Robot::Tree::TreeNode*,
    std::allocator<cs371p::prog::robowars4::Robot::Tree::TreeNode*> >]()',
    which
    is of non-class type `cs371p::prog::robowars4::Robot::Tree::TreeNode*'

    The line of code looks like this:
    vector< TreeNode *>::iterator p1;
    for(p1 = children->begin();p1 != children->end();++p1)
    This LINE RIGHT HERE->>>> p1->payload->getX();

    Please, lemme know what you think any feed back is appreciated

    --Chad
     
    Chad E. Dollins, Nov 8, 2005
    #1
    1. Advertising

  2. Chad E. Dollins

    Kai-Uwe Bux Guest

    Chad E. Dollins wrote:

    >
    > Hello someone said that I should check this forum out for help to my c++
    > problems.
    >
    > I will admit at this point I may have really ran myself into the ground
    > with this code that I am writing, but I'm hoping for a little help from
    > you guys.
    >
    > I have a class that needs use of a bread-first search of a quareney tree.
    > In this class I have a nested class that should be the implementation of a
    > tree that contains two nested classes of its own. Those two classes are a
    > Position representation of cartestian coordinate with accessors and
    > modifiers and comparison methods. The other inner class is a treenode
    > class. This class holds several things, first of all a * to a vector of
    > TreeNode * that represent children nodes, A Position as its Payload, A *
    > to the parent TreeNode, and * pointer to a Maze object no mentioned above.
    >
    > So, my problem is that as I iterate over my children vector I would like
    > to access the payload members accessors of the current treenode in the
    > vector. Except I get this instead:
    > error: request for member `payload' in `
    > *(&p1)->__gnu_cxx::__normal_iterator<_Iterator,
    > _Container>::eek:perator->
    > [with _Iterator = cs371p::prog::robowars4::Robot::Tree::TreeNode**,
    > _Container =
    > std::vector<cs371p::prog::robowars4::Robot::Tree::TreeNode*,
    > std::allocator<cs371p::prog::robowars4::Robot::Tree::TreeNode*> >]()',
    > which
    > is of non-class type `cs371p::prog::robowars4::Robot::Tree::TreeNode*'
    >
    > The line of code looks like this:
    > vector< TreeNode *>::iterator p1;
    > for(p1 = children->begin();p1 != children->end();++p1)
    > This LINE RIGHT HERE->>>> p1->payload->getX();


    Try
    (*p1)->payload->getX();

    Keep in mind: p1 is an iterator; *p1 is the element of the vector it
    designates; this element is itself a pointer pointing to some element that
    presumably has a member "payload".

    >
    > Please, lemme know what you think any feed back is appreciated
    >
    > --Chad



    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Nov 8, 2005
    #2
    1. Advertising

  3. Ok same question as before accept this temp trying to call member function
    with from an index of the vector<TreeNode * > * myMoves
    error ridden code:

    myMoves[x]->makeChildren();


    On Mon, 7 Nov 2005, Kai-Uwe Bux wrote:

    > Chad E. Dollins wrote:
    >
    >>
    >> Hello someone said that I should check this forum out for help to my c++
    >> problems.
    >>
    >> I will admit at this point I may have really ran myself into the ground
    >> with this code that I am writing, but I'm hoping for a little help from
    >> you guys.
    >>
    >> I have a class that needs use of a bread-first search of a quareney tree.
    >> In this class I have a nested class that should be the implementation of a
    >> tree that contains two nested classes of its own. Those two classes are a
    >> Position representation of cartestian coordinate with accessors and
    >> modifiers and comparison methods. The other inner class is a treenode
    >> class. This class holds several things, first of all a * to a vector of
    >> TreeNode * that represent children nodes, A Position as its Payload, A *
    >> to the parent TreeNode, and * pointer to a Maze object no mentioned above.
    >>
    >> So, my problem is that as I iterate over my children vector I would like
    >> to access the payload members accessors of the current treenode in the
    >> vector. Except I get this instead:
    >> error: request for member `payload' in `
    >> *(&p1)->__gnu_cxx::__normal_iterator<_Iterator,
    >> _Container>::eek:perator->
    >> [with _Iterator = cs371p::prog::robowars4::Robot::Tree::TreeNode**,
    >> _Container =
    >> std::vector<cs371p::prog::robowars4::Robot::Tree::TreeNode*,
    >> std::allocator<cs371p::prog::robowars4::Robot::Tree::TreeNode*> >]()',
    >> which
    >> is of non-class type `cs371p::prog::robowars4::Robot::Tree::TreeNode*'
    >>
    >> The line of code looks like this:
    >> vector< TreeNode *>::iterator p1;
    >> for(p1 = children->begin();p1 != children->end();++p1)
    >> This LINE RIGHT HERE->>>> p1->payload->getX();

    >
    > Try
    > (*p1)->payload->getX();
    >
    > Keep in mind: p1 is an iterator; *p1 is the element of the vector it
    > designates; this element is itself a pointer pointing to some element that
    > presumably has a member "payload".
    >
    >>
    >> Please, lemme know what you think any feed back is appreciated
    >>
    >> --Chad

    >
    >
    > Best
    >
    > Kai-Uwe Bux
    >
     
    Chad E. Dollins, Nov 8, 2005
    #3
  4. Chad E. Dollins

    Kai-Uwe Bux Guest

    Chad E. Dollins wrote:

    >
    > Ok same question as before accept this temp trying to call member function
    > with from an index of the vector<TreeNode * > * myMoves
    > error ridden code:
    >
    > myMoves[x]->makeChildren();


    You just need to keep track of the types involved:

    myMoves is a *pointer* to a *vector* of *pointers*. Thus, first dereference
    (now you have a vector) then use the subscript operator (now you have a
    pointer), then dereference again to call the member function.

    ((*myMoves)[x])->makeChildren();


    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Nov 8, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pmatos
    Replies:
    6
    Views:
    23,967
  2. Replies:
    8
    Views:
    1,970
    Csaba
    Feb 18, 2006
  3. Javier
    Replies:
    2
    Views:
    593
    James Kanze
    Sep 4, 2007
  4. pataphor
    Replies:
    0
    Views:
    441
    pataphor
    Jun 14, 2009
  5. Geoff

    Evaluating nester variables

    Geoff, Nov 13, 2003, in forum: Perl Misc
    Replies:
    11
    Views:
    164
    Uri Guttman
    Nov 14, 2003
Loading...

Share This Page