Template problem

Discussion in 'C++' started by mfabricius@gmail.com, Feb 21, 2007.

  1. Guest

    Hi,

    I am trying to compile somebody elses code (he is not available).
    The code won't compile and I do not understand why

    --SNIP--
    //-----------------------------------------------------------------
    // shell_t::rve
    //-----------------------------------------------------------------
    template <class V, class E, class F>
    void shell_t<V, E, F>::rve(vert_t<V, E, F>* v1, edge_t<V, E, F>* e1)
    {
    ....
    //no complain
    edge_t< V, E, F >* et;

    //no complain
    list< double >::iterator di;
    //no complain
    list< list<double> >::iterator ldi;
    //no complain
    list< list<double>* >::iterator ldip;

    //no complain
    list< edge_t< int, int, int > >::iterator let;

    //COMPILE ERROR FOLLOWS NEXT LINE
    list< edge_t< V, E, F >* >::iterator itr;

    for(itr = edges.begin(); itr != edges.end(); itr++)
    {
    if ((*itr) == e1 || (*itr)->twin() == e1)
    {
    edges.erase(itr);
    delete e1;
    break;
    }
    }

    --SNIP, SNIP---


    Here the compiler error (g++-4.1, tried g++-3.95 as well):

    he.cc: In member function 'void halfedge::shell_t<V, E,
    F>::rve(halfedge::vert_t<V, E, F>*, halfedge::edge_t<V, E, F>*)':
    he.cc:294: error: expected `;' before 'itr'
    he.cc:296: error: 'itr' was not declared in this scope
    he.cc:306: error: expected `;' before 'itr'


    Any ideas?

    Max
     
    , Feb 21, 2007
    #1
    1. Advertising

  2. Piyo Guest

    wrote:

    >
    > //COMPILE ERROR FOLLOWS NEXT LINE
    > list< edge_t< V, E, F >* >::iterator itr;
    >

    try this:

    typename list< edge_t< V, E, F >* >::iterator itr;
     
    Piyo, Feb 21, 2007
    #2
    1. Advertising

  3. wrote:
    > I am trying to compile somebody elses code (he is not available).
    > The code won't compile and I do not understand why
    >
    > --SNIP--
    > //-----------------------------------------------------------------
    > // shell_t::rve
    > //-----------------------------------------------------------------
    > template <class V, class E, class F>
    > void shell_t<V, E, F>::rve(vert_t<V, E, F>* v1, edge_t<V, E, F>* e1)
    > {
    > ...
    > [..]
    > //COMPILE ERROR FOLLOWS NEXT LINE
    > list< edge_t< V, E, F >* >::iterator itr;


    I think because 'edge_t' is a dependent type, 'list' is as well, and
    the use of its member requires 'typename':

    typename list< blah >::iterator itr;

    >
    > for(itr = edges.begin(); itr != edges.end(); itr++)
    > {
    > if ((*itr) == e1 || (*itr)->twin() == e1)
    > {
    > edges.erase(itr);
    > delete e1;
    > break;
    > }
    > }
    >
    > --SNIP, SNIP---
    >
    >
    > Here the compiler error (g++-4.1, tried g++-3.95 as well):
    >
    > he.cc: In member function 'void halfedge::shell_t<V, E,
    >>>> rve(halfedge::vert_t<V, E, F>*, halfedge::edge_t<V, E, F>*)':

    > he.cc:294: error: expected `;' before 'itr'
    > he.cc:296: error: 'itr' was not declared in this scope
    > he.cc:306: error: expected `;' before 'itr'
    >
    >
    > Any ideas?


    Read about dependent names in the FAQ.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Feb 21, 2007
    #3
    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. Chris Theis
    Replies:
    2
    Views:
    482
    Chris Theis
    Jul 24, 2003
  2. tom_usenet
    Replies:
    0
    Views:
    540
    tom_usenet
    Jul 24, 2003
  3. Replies:
    1
    Views:
    2,117
    Gianni Mariani
    Jun 8, 2007
  4. Peng Yu
    Replies:
    3
    Views:
    782
    Thomas J. Gritzan
    Oct 26, 2008
  5. nguillot
    Replies:
    5
    Views:
    534
Loading...

Share This Page