Accessing members of template class

  • Thread starter Lucas Kanebley Tavares
  • Start date
L

Lucas Kanebley Tavares

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, bool> old_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::eek:ld_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
 
K

kwikius

Lucas Kanebley Tavares said:
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, bool> old_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::eek:ld_nodes old_node;

^^^

typename T::eek:ld_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, bool> old_nodes;

doesnt need typename

typedef std::map<ds_node, bool> old_nodes;

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

regards
Andy Little
 
R

red floyd

Lucas said:
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, bool> old_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::eek:ld_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-lite/how-to-post.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::eek:ld_nodes old_node;
 
L

Lucas Kanebley Tavares

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, bool> old_nodes;
doesnt need typename
typedef std::map<ds_node, bool> old_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
 
K

kwikius

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top