passing a templated struct...

Discussion in 'C++' started by Toby, Dec 7, 2005.

  1. Toby

    Toby Guest

    Hail and well met.

    I am trying to pass a templated struct to another template. Ex:

    template <class VertexType>
    struct EdgeNode {
    VertexType index;
    int weight;
    };

    template <class VertexType>
    struct VertexNode {
    VertexType info;
    UnsortedType<EdgeNode<VertexType>> edgeList;
    };

    is this not legal? I am getting an error along the lines of:

    c:\documents and settings\toby\my
    documents\cpp\assignment6\graphtypelinked.h(16) : error C2146: syntax
    error : missing ',' before identifier 'edgeList'

    among others.
     
    Toby, Dec 7, 2005
    #1
    1. Advertising

  2. Toby

    Jay Nabonne Guest

    On Wed, 07 Dec 2005 23:34:00 +0000, Toby wrote:

    > Hail and well met.
    >
    > I am trying to pass a templated struct to another template. Ex:
    >
    > template <class VertexType>
    > struct EdgeNode {
    > VertexType index;
    > int weight;
    > };
    >
    > template <class VertexType>
    > struct VertexNode {
    > VertexType info;
    > UnsortedType<EdgeNode<VertexType>> edgeList;

    Try:
    UnsortedType<EdgeNode<VertexType> > edgeList;
    > };
    >

    Note the extra space between the '>'s.

    - Jay
     
    Jay Nabonne, Dec 7, 2005
    #2
    1. Advertising

  3. Toby

    Toby Guest

    Jay Nabonne wrote:
    > On Wed, 07 Dec 2005 23:34:00 +0000, Toby wrote:
    >
    >
    >>Hail and well met.
    >>
    >>I am trying to pass a templated struct to another template. Ex:
    >>
    >>template <class VertexType>
    >>struct EdgeNode {
    >> VertexType index;
    >> int weight;
    >>};
    >>
    >>template <class VertexType>
    >>struct VertexNode {
    >> VertexType info;
    >> UnsortedType<EdgeNode<VertexType>> edgeList;

    >
    > Try:
    > UnsortedType<EdgeNode<VertexType> > edgeList;
    >
    >>};
    >>

    >
    > Note the extra space between the '>'s.
    >
    > - Jay


    It worked! Interesting.... Well thank you very much! I don't understand
    why that tiny whitespace made a difference though... ?
    Thanks!

    -Toby
     
    Toby, Dec 7, 2005
    #3
  4. Toby

    Jay Nabonne Guest

    On Wed, 07 Dec 2005 23:53:47 +0000, Toby wrote:

    > Jay Nabonne wrote:
    >> On Wed, 07 Dec 2005 23:34:00 +0000, Toby wrote:
    >>> UnsortedType<EdgeNode<VertexType>> edgeList;

    >>
    >> Try:
    >> UnsortedType<EdgeNode<VertexType> > edgeList;
    >>
    >>>};
    >>>

    >>
    >> Note the extra space between the '>'s.
    >>
    >> - Jay

    >
    > It worked! Interesting.... Well thank you very much! I don't understand
    > why that tiny whitespace made a difference though... ?
    > Thanks!
    >


    I believe it has to do with C++ using a "greedy" parser. Which means it
    will see those consecutive '>'s as a single ">>" token instead of as two
    separate '>' tokens.

    - Jay
     
    Jay Nabonne, Dec 8, 2005
    #4
  5. Toby

    Toby Guest

    Jay Nabonne wrote:
    > On Wed, 07 Dec 2005 23:53:47 +0000, Toby wrote:
    >
    >
    >>Jay Nabonne wrote:
    >>
    >>>On Wed, 07 Dec 2005 23:34:00 +0000, Toby wrote:
    >>>
    >>>> UnsortedType<EdgeNode<VertexType>> edgeList;
    >>>
    >>>Try:
    >>> UnsortedType<EdgeNode<VertexType> > edgeList;
    >>>
    >>>
    >>>>};
    >>>>
    >>>
    >>>Note the extra space between the '>'s.
    >>>
    >>>- Jay

    >>
    >>It worked! Interesting.... Well thank you very much! I don't understand
    >>why that tiny whitespace made a difference though... ?
    >>Thanks!
    >>

    >
    >
    > I believe it has to do with C++ using a "greedy" parser. Which means it
    > will see those consecutive '>'s as a single ">>" token instead of as two
    > separate '>' tokens.
    >
    > - Jay
    >

    Makes sense. Thanks again! (and i really appreciate your speedy
    assistance, as this assignment is due tomorrow morning ;-] )

    -toby
     
    Toby, Dec 8, 2005
    #5
    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. RA Scheltema
    Replies:
    3
    Views:
    413
    RA Scheltema
    Jan 6, 2004
  2. Marijn
    Replies:
    5
    Views:
    484
    Marijn
    Feb 13, 2004
  3. Replies:
    0
    Views:
    2,263
  4. Amadeus W. M.
    Replies:
    2
    Views:
    408
    Amadeus W. M.
    Jul 4, 2006
  5. Replies:
    1
    Views:
    313
Loading...

Share This Page