Re: CMAP under vs2005+
Giovanni Dicanio wrote:
"Tommy" <tommy767@gmail.com> ha scritto nel messaggio
news:udfkiT1NJHA.1148@TK2MSFTNGP05.phx.gbl...
This does work when you declare it as a
typedef. Like in the example you have:
typedef MyMap< string, string > CMyMapString;
Tommy: what you showed is not polymorphism, as David already wrote and
explained.
Right, I didn't wish to imply using the typedef makes this polymorphic.
I'm an old school programmer with 20+ years of basic level C/C++
knowledge so I always thought that adding a class "wrapper" to an
existing object which contains virtual methods was the basic act in
polymorphism. I have a lot of polymorphism in my code. I have a lot
of virtual I/O interfaces, for examples. Lots of long stable code
long engineered for reusability.
With the current compilers being more "template driven", I think my
lack of expertise in templates does not help, which to me, I already
felt it was a matter and decision of mixing "more expanded code" thus
the basic idea of a Template versus reusability, virtual tables, etc.
My problem now is all my code engineered over many years is "suddenly"
broken under VS2005. Some are legit strong(er) C/C++ syntax
highlights. Others compiler errors (and warnings) are less obvious.
So I am going to a period of tying to understand the subtle
differences and why I need to make changes. Sometimes you just made
the "change" necessary, and generally, you shoot for transparency but
this is now more than a simple "change" as it now may alter some
fundamental engineering.
For example, I have code which uses CMapEx in a class object,
class TMailHost {
public:
// Now using new mapex.h
//CMapEx<CString, const char *> inTrans;
CMapEx<CString> inTrans;
};
and functions, including multi-threaded code that use it like so:
BOOL FuncXYZ(const TMailHost &mh)
{
...
CString v;
if (mh.inTrans.Lookup("SomeKey",v)) {
....
}
}
BOOL FuncABC(void *p)
{
...
const TMailHost &mh = *(TMailHost *)p;
CString v;
if (mh.inTrans.Lookup("SomeKey",v)) {
....
}
}
well, the compiler (old and new) is now complaining with the new CMapEx:
error C2662: 'Lookup' : cannot convert 'this' pointer from
'const class CMapEx<class CString>' to
'class CMapEx<class CString> &'
Conversion loses qualifiers
I even tried it with your dictionary.h version.
Changing the function prototype to
BOOL wcUser(TMailHost &mh)
resolves this, but I need to know why before changes are made globally.
I know right now that some code that uses the new CMapEx is
intermittently now producing odd results.
So I think that I need to take a step back and further study the usage
of std c/c++ containers and classes, especially the mixed usages with
MFC and also its history in multi-threaded environment, i.e., how
thread-safe are they?
Anyway, thanks. I have to understand the "why's" above and any
repercussions before I can make use of std classes/templates.
--