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

STL typedefs and base class pointer problem

P: n/a
Suppose I have these 4 typedefs, where each of the 2nd parameter in
each is a simple class that just contains a different number of strings:

typedef map < char*, cctrlrec_data, ltstr > ctrlrec_table2;
typedef map < char*, ctyperec_data, ltstr > typerec_table2;
typedef map < char*, chotrec_data, ltstr > hotrec_table2;
typedef map < char*, cmtxtrec_data, ltstr > mtxtrec_table2;

I have a stream of XML data coming across a socket and I want to parse
it out into instances of cctrlrec_data, ctyperec_data, chotrec_data, or
cmtxtrec_data, which then will be stuffed into the appropriate typedef'd
map.

My parser will tell me which kind of object to instantiate, and
it produces the data for a number of each in series but does mix
them up in series.

eg: parser output is:
-- start parsing
cctrlrec_data strings
..
..
..
cctrlrec_data strings
ctyperec_data strings
..
..
..
ctyperec_data strings
chotrec_data strings
..
..
..
chotrec_data strings
cmtxtrec_data strings
..
..
..
cmtxtrec_data strings
-- done parsing

I'd like to have a pointer that I could just change to point at the
appropriate map when the parser code starts producing a different
type of output object.

A pointer to the base class seems ideal for this.

But how does one declare a pointer to the base class when that is a
template class? Can one do this? Am I completely out to lunch, & should
consider some other method of doing this? ;-)

TIA!
Eric
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

I'd like to have a pointer that I could just change to point at the
appropriate map when the parser code starts producing a different
type of output object.
Just curious, how do u plan to use this ptr in your code?

A pointer to the base class seems ideal for this.


Jul 19 '05 #2

P: n/a
On 7 Aug 2003 14:44:58 -0700, em****@hotmail.com (emerth) wrote:
Suppose I have these 4 typedefs, where each of the 2nd parameter in
each is a simple class that just contains a different number of strings:

typedef map < char*, cctrlrec_data, ltstr > ctrlrec_table2;
typedef map < char*, ctyperec_data, ltstr > typerec_table2;
typedef map < char*, chotrec_data, ltstr > hotrec_table2;
typedef map < char*, cmtxtrec_data, ltstr > mtxtrec_table2;
The keys should probably be something like std::strting, or you'll
BURG.
A pointer to the base class seems ideal for this.
You are wanting to use STL polymorphically. You can't; STL isn't
object-oriented.
But how does one declare a pointer to the base class when that is a
template class? Can one do this? Am I completely out to lunch, & should
consider some other method of doing this? ;-)


Consider a new method. Here's the thing: ctrlrec_table2 (etc) has no
base class; at least not one defined by the standard. (eg, if your
implementation of std::map is derived from something, that's
implementation-specific) Templated types aren't derived from base
classes. Each concrete instance of a template is it's own, seperate
thing.

Here's an example:

<code>
template<typename T>
class templ
{
void f();
};

typedef templ<float> my_float_templ;
</code>

my_float_templ doesn't have a base class. It's not derived from
anything.

</dib>
John Dibling
Witty banter omitted for your protection
Jul 19 '05 #3

P: n/a
> template<typename T>
class templ
{
void f();
};

typedef templ<float> my_float_templ;
</code>

my_float_templ doesn't have a base class. It's not derived from
anything.


Yes, I understand. Your example is most helpful. Thankyou very much!
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.