473,395 Members | 1,497 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.

Accessing members of template class

Ok, I found a lot of similar errors to this on the net (and here), but
none just like it.

What I have is a bunch of classes that define a few members, for
isntance:

class ds_node {
____public:
________typedef typename std::map<ds_node, boolold_nodes;
________static ds_node *first(fsm_core &m);
________static ds_node *next(fsm_core &m, ds_node &node, int input);
..... (a bunch of stuff goes here) ...
};

and another templated class which is suppose to use those previously
defined classes.

template <class T>
class suc_tree {
____public:
____void run(fsm_core &m);
....
};

template <class T>
void suc_tree<T>::run(fsm_core &m) {
____T::old_nodes old_node;

____T *cur = T::first(m);
.....
}

and I was wondering if this is doable without using inheritance and/or
what would be the suggested methods to go about doing this. The error
I'm getting is:
suctree.hpp|47|error: expected `;' before "old_node" (line 47 =
old_node declaration).
suctree.hpp|64|error: `old_node' was not declared in this scope (line
64 = old_node first use)

After that I get a LOT of STL related errors, but I suppose that once
these are fixed they'll go away. And as I get no errors from calling
first or next, I suppose that I shouldn't get any while declaring
old_node.

Thanks in advance.
Lucas
Jun 27 '08 #1
5 1244

"Lucas Kanebley Tavares" <lu*****@gmail.comwrote in message
news:a8**********************************@y21g2000 hsf.googlegroups.com...
Ok, I found a lot of similar errors to this on the net (and here), but
none just like it.

What I have is a bunch of classes that define a few members, for
isntance:

class ds_node {
public:
typedef typename std::map<ds_node, boolold_nodes;
static ds_node *first(fsm_core &m);
static ds_node *next(fsm_core &m, ds_node &node, int input);
..... (a bunch of stuff goes here) ...
};
<...>
template <class T>
void suc_tree<T>::run(fsm_core &m) {
T::old_nodes old_node;

^^^

typename T::old_nodes old_node;

Not sure about the rest but needs "typename" if old_nodes is a typename...

and BTW

typedef typename std::map<ds_node, boolold_nodes;

doesnt need typename

typedef std::map<ds_node, boolold_nodes;

typename is used for expressions that are dependent types, and only in
templates.

regards
Andy Little
Jun 27 '08 #2
Lucas Kanebley Tavares wrote:
Ok, I found a lot of similar errors to this on the net (and here), but
none just like it.

What I have is a bunch of classes that define a few members, for
isntance:

class ds_node {
____public:
________typedef typename std::map<ds_node, boolold_nodes;
________static ds_node *first(fsm_core &m);
________static ds_node *next(fsm_core &m, ds_node &node, int input);
..... (a bunch of stuff goes here) ...
};

and another templated class which is suppose to use those previously
defined classes.

template <class T>
class suc_tree {
____public:
____void run(fsm_core &m);
....
};

template <class T>
void suc_tree<T>::run(fsm_core &m) {
____T::old_nodes old_node;

____T *cur = T::first(m);
.....
}

and I was wondering if this is doable without using inheritance and/or
what would be the suggested methods to go about doing this. The error
I'm getting is:
suctree.hpp|47|error: expected `;' before "old_node" (line 47 =
old_node declaration).
suctree.hpp|64|error: `old_node' was not declared in this scope (line
64 = old_node first use)

After that I get a LOT of STL related errors, but I suppose that once
these are fixed they'll go away. And as I get no errors from calling
first or next, I suppose that I shouldn't get any while declaring
old_node.
Your cut&paste really bad, with the leading underscores, and you didn't
follow FAQ 5.8
(http://www.parashift.com/c++-faq-lit....html#faq-5.8), by
posting complete compileable (except for the error) code.

However, this is a fairly common error (FAQ 35.18 --
http://www.parashift.com/c++-faq-lit...html#faq-35.18)

old_nodes is a *dependent* name -- to wit, the compiler can't know that
it's a type without some help from you. Change the line in question to:

typename T::old_nodes old_node;
Jun 27 '08 #3
Thank you both for the replies, that is now solved.

Regarding the posting, I put the underscores in because I thought
they'd help. As for posting the complete codes, those classes are 100+
lines each, and I thought it might upset people and would break
guideline #3 - Post minimal code (which I had never read, but was
common sense). Next time, I'll try to keep code to a minimum while,
providing a compilable one.
>and BTW
typedef typename std::map<ds_node, boolold_nodes;
doesnt need typename
typedef std::map<ds_node, boolold_nodes;
typename is used for expressions that are dependent types, and only in
templates.
Heh, I actually added it right before I was posted the code here, just
to rule that out. There wasn't that type name there before :P. Thanks
for the final tip though, I didn't know it'd only be useful around
templates.

Lucas

PS: Ugh, almost top-posted. Not used to posting here! heh

On 13 maio, 16:35, red floyd <no.s...@here.dudewrote:
Lucas Kanebley Tavares wrote:
Ok, I found a lot of similar errors to this on the net (and here), but
none just like it.
What I have is a bunch of classes that define a few members, for
isntance:
class ds_node {
____public:
________typedef typename std::map<ds_node, boolold_nodes;
________static ds_node *first(fsm_core &m);
________static ds_node *next(fsm_core &m, ds_node &node, int input);
..... (a bunch of stuff goes here) ...
};
and another templated class which is suppose to use those previously
defined classes.
template <class T>
class suc_tree {
____public:
____void run(fsm_core &m);
....
};
template <class T>
void suc_tree<T>::run(fsm_core &m) {
____T::old_nodes old_node;
____T *cur = T::first(m);
.....
}
and I was wondering if this is doable without using inheritance and/or
what would be the suggested methods to go about doing this. The error
I'm getting is:
suctree.hpp|47|error: expected `;' before "old_node" (line 47 =
old_node declaration).
suctree.hpp|64|error: `old_node' was not declared in this scope (line
64 = old_node first use)
After that I get a LOT of STL related errors, but I suppose that once
these are fixed they'll go away. And as I get no errors from calling
first or next, I suppose that I shouldn't get any while declaring
old_node.

Your cut&paste really bad, with the leading underscores, and you didn't
follow FAQ 5.8
(http://www.parashift.com/c++-faq-lit....html#faq-5.8), by
posting complete compileable (except for the error) code.

However, this is a fairly common error (FAQ 35.18 --http://www.parashift.com/c++-faq-lite/templates.html#faq-35.18)

old_nodes is a *dependent* name -- to wit, the compiler can't know that
it's a type without some help from you. Change the line in question to:

typename T::old_nodes old_node;
Jun 27 '08 #4

"Lucas Kanebley Tavares" <lu*****@gmail.comwrote in message
news:94**********************************@l64g2000 hse.googlegroups.com...

<...>
Heh, I actually added it right before I was posted the code here, just
to rule that out. There wasn't that type name there before :P. Thanks
for the final tip though, I didn't know it'd only be useful around
templates.

Yep. In fact typename was added to C++ just to make templates absolutely
impossible for the beginner to use, (as were the epic error messages)
Needless to say in practise typename exceeded all expectations as to how
well it would do its job...

Only Joking ....:-)

regards
Andy Little
Jun 27 '08 #5
On May 13, 9:35 pm, red floyd <no.s...@here.dudewrote:
Lucas Kanebley Tavares wrote:
[...]
Your cut&paste really bad, with the leading underscores,
Which may be just to prevent reformatting by news, somewhere
along the road.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alexandre Tolmos | last post by:
Hi all, I can't compile the following code with Gcc 3.3 (compiles with CodeWarrior 8): template <typename T = int> class Boule { friend class Boule<int>; friend class Boule<float>;
25
by: John Harrison | last post by:
This code fails to compile on Comeau C++ and VC++ 7.1 (with language extensions disabled) template <class T> struct B { T b; }; template <class T>
3
by: Gianni Mariani | last post by:
I was a little surprised by this: It seems like the code below should not compile but the Comeau 4.3.3 compiler accepts it and the gcc 3.4(prerel) compiler rejects it and MSVC++7.1 ICE's. ...
2
by: Simon White | last post by:
Hi, I have code that looks legal to me and has compiled for years and on latest VC, etc compilers. Just recently gcc made a change to their compiler (3.4) that broke it. I don't have access to...
2
by: Steven T. Hatton | last post by:
I find the surprising. If I derive Rectangle from Point, I can access the members of Point inherited by Rectangle _IF_ they are actually members of a Rectangle. If I have a member of type Point...
10
by: Zap | last post by:
Widespread opinion is that public data members are evil, because if you have to change the way the data is stored in your class you have to break the code accessing it, etc. After reading this...
4
by: Amit Limaye | last post by:
Hello, i have a class with around 10-15 properties and i want to write a single set get pair to access all these properties. Any suggestions. BTW this is not some question for an interview. I was...
2
by: flopbucket | last post by:
Hi, If I have the following: template<class T> class A { public: int a; };
3
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.