Hi Bob,
I believe that Doug had provided concise and helpful answers here. I just
would like to add additional comments regarding one of your concerns, "The
downside (such as it is) of having a map of structures is having
to add a default constructor and a copy constructor to my structure.".
Generally you need not to add a default constructor and a copy constructor
to your structure since complier will do it implicitly (mostly bitwise
copy). You can simply perform a test with the following code:
struct MyStruct
{
int m_i;
int* p_i;
};
int _tmain(int argc, _TCHAR* argv[])
{
MyStruct s;
int n = 100;
s.m_i = 10;
s.p_i = &n;
map<int, MyStruct> myMap;
myMap[0]=s;
printf("%d,%d",myMap[0].m_i,*(myMap[0].p_i));
getchar();
return 0;
}
Whether or not to use a copy constructor depends on situations. When a
class does not allow/need to use bitwise copy semantics, you need to
explicitly write a copy constructor. I would like to recommend a famous
book (written by Stanley B.Lippman) for you "Inside The C++ Object Model"
(
http://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp/0201834545).
You can read the chapter "The senmantics of constructors" in which Stanley
listed four typical situations that do not need "Bitwise Copy Semantics".
Generally they are the following:
1) Member class object having copy constructor
2) Base class having copy constructor
3) Class having one or more virtual functions
4) Derived class having one or more virtual base classes
Hope this helps.
Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================