By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,421 Members | 1,127 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,421 IT Pros & Developers. It's quick & easy.

passing a templated struct...

P: n/a
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.
Dec 7 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
Dec 7 '05 #2

P: n/a
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
Dec 8 '05 #3

P: n/a
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

Dec 8 '05 #4

P: n/a
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
Dec 8 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.