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

pointer is std:map - broke in port from VS6 to .NET - A little Help?

Hi everyone,

In my attempt to port code from VS 6.0 to VS.NET I had some code break along
the way, mostly due to not adhereing closely to the C++ standard. This may
be another instance but I can't think of a good fix, or even why it broke.

The problem

In one of my CFormView derived classes I have a member variable of the
type...

std::map<geom_base *, mass_props> mass_prop_map;

which I populate like...

mass_prop_map.insert(pair<geom_base *, mass_props>(af, mass_props(volume,
mass, weight, surface_area)));
where "mass_props" is a class whose constructor is called during the
"insert" shown above.
and "af" is a pointer to a class object that is derived from "geom_base"

I use the map to populated controls on the view with data from only certain
geom_base derived objects (ones that meet certain critera)

The .NET compiler doesn't like the std::map<geom_base *, mass_props>
mass_prop_map; variable declaration - it wouldn't compile.
If I change "geom_base *" to "geom_base" (and change the insert to reflect
the change) it will compile OK but in execution it will force a copy to be
made of the "af" object, which is quite huge and I don't need a local copy
inside the CFormView derived class, it would be a waste.

Am I breaking the rules again by using a pointer as a key type inside a
std::map? I don't see anything in the online-docs (MSDN) that says you
can't. Again, this worked fine inside VS 6.0.
Does anyone have any idea what is wrong and what is a work-around?

In the words of James Ingram: "I did my best but I guess my best wasn't
goooooood enough"


Nov 16 '05 #1
3 3664
Pointer as a key-type for std::map is perfectly legal. Can you post a small
but complete example that illustrates the error you're running into?

-cd

Dan Trowbridge wrote:
Hi everyone,

In my attempt to port code from VS 6.0 to VS.NET I had some code
break along the way, mostly due to not adhereing closely to the C++
standard. This may be another instance but I can't think of a good
fix, or even why it broke.

The problem

In one of my CFormView derived classes I have a member variable of the
type...

std::map<geom_base *, mass_props> mass_prop_map;

which I populate like...

mass_prop_map.insert(pair<geom_base *, mass_props>(af,
mass_props(volume, mass, weight, surface_area)));
where "mass_props" is a class whose constructor is called during the
"insert" shown above.
and "af" is a pointer to a class object that is derived from
"geom_base"

I use the map to populated controls on the view with data from only
certain geom_base derived objects (ones that meet certain critera)

The .NET compiler doesn't like the std::map<geom_base *, mass_props>
mass_prop_map; variable declaration - it wouldn't compile.
If I change "geom_base *" to "geom_base" (and change the insert to
reflect the change) it will compile OK but in execution it will
force a copy to be made of the "af" object, which is quite huge and I
don't need a local copy inside the CFormView derived class, it would
be a waste.

Am I breaking the rules again by using a pointer as a key type inside
a std::map? I don't see anything in the online-docs (MSDN) that says
you can't. Again, this worked fine inside VS 6.0.
Does anyone have any idea what is wrong and what is a work-around?

In the words of James Ingram: "I did my best but I guess my best
wasn't goooooood enough"

Nov 16 '05 #2
Carl,

Well I did it in a seperate project and, don't you know it, it works fine
with the simple classes. Here is my sample code:
class fred
{
public:
fred() {};
virtual ~fred() {};
};
class pebbles : public fred
{
public:
pebbles() : fred() {};
virtual ~pebbles() {};
};
class barney
{
public:
barney() {};
virtual ~barney() {};
};
int main(int argc, char* argv[])
{
std::map<fred *, barney> flintstones;
pebbles * pebbles_pointer = new pebbles();
flintstones.insert( pair<fred *, barney >( pebbles_pointer,
barney() ) );
std::map<fred *, barney>::iterator fi;
fi = flintstones.find(pebbles_pointer);
return(0);
}

Since I first posted this I have changed the std::map<geom_base *,
calc_mass_props> usage to deque<pair< geom_base *, calc_mass_props> > and
then wrote my own "find" code to look up things I needed. This new method
works good but required a little extra coding. After recieving your post I
went back and changed everything back to std::map<geom_base *, mass_props>
and things are still not compiling. So I have a working version of the code
by using the "deque method" but it would still be nice to know why the more
eligant "map method" didn't work. If you care to consider what may be
wrong, the following is the error codes that the compiler gives me but don't
knock yourself out over it since I can always sue the "deque method" (but is
does sort-of make you want to stear clear of std::map :-) )...

(NOTE: In my original post I said the "data" member of the map was of type
"mass_props" in reallity it is of type "calc_mass_props". I change the name
in the original post because I wanted to avoid confusion becasue I was
afraid that "calc_mass_props(volume, mass, weight, surface_area)" could look
like a function call and not a constructor in the line:
mass_prop_map.insert( pair<geom_base *, calc_mass_props >( af,
calc_mass_props(volume, mass, weight, surface_area) ) );
The error codes provided below have the original(true) class names (i.e.
"calc_mass_props" not "mass_props")

geom_audit_view.cpp
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(1133) :
error C2061: syntax error : identifier '_Wherenode'
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xtree(1130) :
while compiling class-template member function
'std::_Tree<_Traits>::_Nodeptr
std::_Tree<_Traits>::_Buynode(std::_Tree<_Traits>: :_Nodeptr,std::_Tree<_Trai
ts>::_Nodeptr,std::_Tree<_Traits>::_Nodeptr,const
std::_Tree<_Traits>::value_type &,char)'
with
[
_Traits=std::_Tmap_traits<geom_base *,calc_mass_props,std::less<geom_base
*>,std::allocator<std::pair<geom_base *const ,calc_mass_props>>,false>
]
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\map(77) : see
reference to class template instantiation 'std::_Tree<_Traits>' being
compiled
with
[
_Traits=std::_Tmap_traits<geom_base *,calc_mass_props,std::less<geom_base
*>,std::allocator<std::pair<geom_base *const ,calc_mass_props>>,false>
]
c:\dan\cwork\sabdev\geom_audit_view.h(91) : see reference to class template
instantiation 'std::map<_Kty,_Ty>' being compiled
with
[
_Kty=geom_base *,
_Ty=calc_mass_props
]

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:ue**************@TK2MSFTNGP12.phx.gbl...
Pointer as a key-type for std::map is perfectly legal. Can you post a small but complete example that illustrates the error you're running into?

-cd

Dan Trowbridge wrote:
Hi everyone,

In my attempt to port code from VS 6.0 to VS.NET I had some code
break along the way, mostly due to not adhereing closely to the C++
standard. This may be another instance but I can't think of a good
fix, or even why it broke.

The problem

In one of my CFormView derived classes I have a member variable of the
type...

std::map<geom_base *, mass_props> mass_prop_map;

which I populate like...

mass_prop_map.insert(pair<geom_base *, mass_props>(af,
mass_props(volume, mass, weight, surface_area)));
where "mass_props" is a class whose constructor is called during the
"insert" shown above.
and "af" is a pointer to a class object that is derived from
"geom_base"

I use the map to populated controls on the view with data from only
certain geom_base derived objects (ones that meet certain critera)

The .NET compiler doesn't like the std::map<geom_base *, mass_props>
mass_prop_map; variable declaration - it wouldn't compile.
If I change "geom_base *" to "geom_base" (and change the insert to
reflect the change) it will compile OK but in execution it will
force a copy to be made of the "af" object, which is quite huge and I
don't need a local copy inside the CFormView derived class, it would
be a waste.

Am I breaking the rules again by using a pointer as a key type inside
a std::map? I don't see anything in the online-docs (MSDN) that says
you can't. Again, this worked fine inside VS 6.0.
Does anyone have any idea what is wrong and what is a work-around?

In the words of James Ingram: "I did my best but I guess my best
wasn't goooooood enough"


Nov 16 '05 #3
Certainly an odd error message you're getting. Without digging into it, the
one thing that pops to mind is that maybe there's a macro in the "real"
project that's clobbering part of the std::map implementation? That kind of
thing can be incredibly hard to track down, but it is possible.

Preprocess one of your files (using cl /P) and then try to compile the
pre-processed output. Assuming you get the same error, you can then examine
that single linear file to see if there's something that doesn't look right
due to a macro, etc. Still tedious, but sometimes an effective strategy.

-cd

Dan Trowbridge wrote:
Carl,

Well I did it in a seperate project and, don't you know it, it works
fine with the simple classes. Here is my sample code:
class fred
{
public:
fred() {};
virtual ~fred() {};
};
class pebbles : public fred
{
public:
pebbles() : fred() {};
virtual ~pebbles() {};
};
class barney
{
public:
barney() {};
virtual ~barney() {};
};
int main(int argc, char* argv[])
{
std::map<fred *, barney> flintstones;
pebbles * pebbles_pointer = new pebbles();
flintstones.insert( pair<fred *, barney >( pebbles_pointer,
barney() ) );
std::map<fred *, barney>::iterator fi;
fi = flintstones.find(pebbles_pointer);
return(0);
}

Since I first posted this I have changed the std::map<geom_base *,
calc_mass_props> usage to deque<pair< geom_base *, calc_mass_props> >
and then wrote my own "find" code to look up things I needed. This
new method works good but required a little extra coding. After
recieving your post I went back and changed everything back to
std::map<geom_base *, mass_props> and things are still not compiling.
So I have a working version of the code by using the "deque method"
but it would still be nice to know why the more eligant "map method"
didn't work. If you care to consider what may be wrong, the
following is the error codes that the compiler gives me but don't
knock yourself out over it since I can always sue the "deque method"
(but is does sort-of make you want to stear clear of std::map :-)
)...

(NOTE: In my original post I said the "data" member of the map was of
type "mass_props" in reallity it is of type "calc_mass_props". I
change the name in the original post because I wanted to avoid
confusion becasue I was afraid that "calc_mass_props(volume, mass,
weight, surface_area)" could look like a function call and not a
constructor in the line: mass_prop_map.insert( pair<geom_base *,
calc_mass_props >( af, calc_mass_props(volume, mass, weight,
surface_area) ) );
The error codes provided below have the original(true) class names
(i.e. "calc_mass_props" not "mass_props")

geom_audit_view.cpp
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\xtree(1133) : error C2061: syntax error : identifier
'_Wherenode'
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\xtree(1130) : while compiling class-template member
function 'std::_Tree<_Traits>::_Nodeptr
std::_Tree<_Traits>::_Buynode(std::_Tree<_Traits>: :_Nodeptr,std::_Tree<_Trai ts>::_Nodeptr,std::_Tree<_Traits>::_Nodeptr,const
std::_Tree<_Traits>::value_type &,char)'
with
[
_Traits=std::_Tmap_traits<geom_base
*,calc_mass_props,std::less<geom_base
*>,std::allocator<std::pair<geom_base *const ,calc_mass_props>>,false>
]
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\map(77) : see reference to class template
instantiation 'std::_Tree<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<geom_base
*,calc_mass_props,std::less<geom_base
*>,std::allocator<std::pair<geom_base *const ,calc_mass_props>>,false>
]
c:\dan\cwork\sabdev\geom_audit_view.h(91) : see reference to class
template instantiation 'std::map<_Kty,_Ty>' being compiled
with
[
_Kty=geom_base *,
_Ty=calc_mass_props
]

"Carl Daniel [VC++ MVP]"
<cp*****************************@mvps.org.nospam > wrote in message
news:ue**************@TK2MSFTNGP12.phx.gbl...
Pointer as a key-type for std::map is perfectly legal. Can you post
a small but complete example that illustrates the error you're
running into?

-cd

Dan Trowbridge wrote:
Hi everyone,

In my attempt to port code from VS 6.0 to VS.NET I had some code
break along the way, mostly due to not adhereing closely to the C++
standard. This may be another instance but I can't think of a good
fix, or even why it broke.

The problem

In one of my CFormView derived classes I have a member variable of
the type...

std::map<geom_base *, mass_props> mass_prop_map;

which I populate like...

mass_prop_map.insert(pair<geom_base *, mass_props>(af,
mass_props(volume, mass, weight, surface_area)));
where "mass_props" is a class whose constructor is called during the
"insert" shown above.
and "af" is a pointer to a class object that is derived from
"geom_base"

I use the map to populated controls on the view with data from only
certain geom_base derived objects (ones that meet certain critera)

The .NET compiler doesn't like the std::map<geom_base *, mass_props>
mass_prop_map; variable declaration - it wouldn't compile.
If I change "geom_base *" to "geom_base" (and change the insert to
reflect the change) it will compile OK but in execution it will
force a copy to be made of the "af" object, which is quite huge and
I don't need a local copy inside the CFormView derived class, it
would
be a waste.

Am I breaking the rules again by using a pointer as a key type
inside
a std::map? I don't see anything in the online-docs (MSDN) that
says you can't. Again, this worked fine inside VS 6.0.
Does anyone have any idea what is wrong and what is a work-around?

In the words of James Ingram: "I did my best but I guess my best
wasn't goooooood enough"

Nov 16 '05 #4

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

Similar topics

24
by: Duane Hebert | last post by:
2 questions: Given a map defined as std::map<int,string> stringmap; //How do you access the data_type (string) via an iterator? std::string spoo("doh");
1
by: Antti Granqvist | last post by:
Hello! I have following object relations: Competition 1--* Category 1--* Course 1 | | * Course
2
by: ash | last post by:
Hi, I'm getting started with STL, and am stuck at creating a map container. I checked one of the texts and found a code in there. To make it simple, i wrote the following: #include...
1
by: Saeed Amrollahi | last post by:
Dear All C++ Programmers Hello I am Saeed Amrollahi. I am a software engineer in Tehran Sewerage Company. I try to use std::map and map::find member function. I use Visual Studio .NET. my...
13
by: jstanforth | last post by:
This is probably a very obvious question, but I'm not clear on what operators need to be implemented for std::map.find() to work. For example, I have a class MyString that wraps std::string, and...
19
by: Erik Wikström | last post by:
First of all, forgive me if this is the wrong place to ask this question, if it's a stupid question (it's my second week with C++), or if this is answered some place else (I've searched but not...
1
by: Maxwell | last post by:
Hello, I having having oodles of trouble using the std lib in my MC++ (VS.NET 2003) Class library. I figured out a simple sample to reproduce the errors I am having. Create a MC++ (VS.NET 2003)...
4
by: Evyn | last post by:
Hi all, I'm starting to fool around with STL and in particular std::map. How do I iterate through one map and insert every pair in another map? I have the following so far: map<double,...
7
by: DevNull | last post by:
Hi there everyone, I'm creating a very simple immediate mode command interpreter. The final purpose is to provide a pluggable control and command console for a MUD server I have written. The...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.