473,395 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

passing a templated struct...

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
4 1445
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Momchil Velikov | last post by:
The following program produces error at the definition of ``b''. However it compiles fine the second (supposedly equivalent) form of the templated constructor. Why the two alternatives aren't...
3
by: RA Scheltema | last post by:
hi all, Basically I have the following situation in my header-file: --- .... template <typename ta_type> struct A
2
by: Thomas Matthews | last post by:
Hi, I would like to create a table (or vector) of pointers to templated functions. 1. How do I declare a typedef of a pointer to a templated function? For example, I have some functions...
2
by: John Stiles | last post by:
I have written some pretty simple code which works great in Dev Studio and CodeWarrior, but gcc is giving me link errors. Here is what I've been able to distill it down to: namespace Private {...
4
by: __PPS__ | last post by:
suppose I have class that has templated operator. I want to have a few overloads/template specializations for different types. Basicly, the biggest problem I have is to be able to have this: ...
2
by: Alex Drummond | last post by:
Hello, Is there any way of specializing a templated function on a type which is itself templated? Here's the simplest example of the problem I can think of. Say I have written an implementation...
2
by: Pete C | last post by:
Hello... I am writing a templated 'wrapper' class that takes as its template parameter a class to be inherited from. I need a specialisation of this wrapper class in certain cases, however I am...
15
by: kwikius | last post by:
Hi all, I have been searching through the list of papers at: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/ I seem to remember a proposal regarding templated namespaces e.g: template...
18
by: tbringley | last post by:
I am a c++ newbie, so please excuse the ignorance of this question. I am interested in a way of having a class call a general member function of another class. Specifically, I am trying to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.