473,394 Members | 1,893 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,394 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 3677
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.