473,320 Members | 1,707 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,320 software developers and data experts.

STL typedefs and base class pointer problem

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
3 4134

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

Similar topics

3
by: tirath | last post by:
Hi all, I have a templated class that derives from a non-templated abstract class. How do I then cast a base class pointer to a <templated> derived class pointer in a generalised fashion? ...
9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
4
by: Gopal-M | last post by:
I have the problem with sizeof operator I also want to implement a function that can return size of an object. My problem is as follows.. I have a Base class, say Base and there are many class...
5
by: Simon Elliott | last post by:
For some time I've been using typedefs for STL containers for reasons outlined in: http://www.gotw.ca/gotw/046.htm However a major downside to this is that you can't forward declare a typedef...
5
by: eiji | last post by:
Hi folks, I hope this is not "off topic"! :-) Consider the next code: /* Declarations of types that could become platform-dependent */ #define MyChar char #define MyInt int
1
by: Michal Wróbel | last post by:
Hello, I've got few questions concerning typedefs inside class definition. Firstly, I'll give an example code: template< class T > class Function { public: typedef boost::shared_ptr<...
3
by: aiooua | last post by:
Any idea why the following code does not compile? ---- #include<iostream> #include<list> using namespace std; class Base { public: int val;
4
by: Grizlyk | last post by:
Hello. Why were base class "typedefs" hidden by template<and explicit usage of them does not work too? Try open only one of the lines in the example below //using Tparent::Tptr; //typedef...
10
by: Dom Jackson | last post by:
I have a program which crashes when: 1 - I use static_cast to turn a base type pointer into a pointer to a derived type 2 - I use this new pointer to call a function in an object of the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.