| Xavax C++ Library | Class Index FAQ Overview |
The copy constructor and assignment operator are declared private to prevent them from being used and to prevent the compiler from generating them automatically. This is done for classes where copying and assignment have no reasonable meaning, or could cause problems with resource management.
#include directives
in the example code followed by filenames that
are not enclosed in double quotes or angle brackets?
These are actually macros defined in Headers.h.
The C preprocessor allows a #include directive
to be followed by a filename enclosed in double quotes
or angle brackets or a macro that evaluates to
a filename enclosed in double quotes or angle brackets.
The Xavax C++ Library exploits this feature as part of an
efficient scheme for protecting against
multiple inclusion of header files.
sizeof(T*)
bytes (typically 4 bytes);
however, the same object can be stored in multiple
containers without the overhead of creating
multiple copies of the object as is the case
when objects are stored by value.
There are two reasons to provide a compare functor.
If type T does not implement operator==
and operator<, the container template
will not be able to generate a default compare functor;
therefore, one must be provided by the user.
The performance of the container can be improved
by providing a compare functor that is more efficient
than the default compare functor which consists
of the following code.
template<class T>
int ClassName<T>::operator()(const T* p1, const T* p2)
{
int result;
if ( *p1 == *p2 )
result = 0;
else if ( *p1 < *p2 )
result = -1;
else
result = 1;
return result;
}
This generic code is inefficient when the element type
or the key embedded in the type is a native numerical
type or a character string.
Here are example compare functors for integers and
character strings that are significantly more
efficient than the default.
int ClassName::operator()(const int* p1, const int* p2)
{
return *p1 - *p2;
}
int ClassName::operator()(const char** p1, const char** p2)
{
return strcmp(*p1, *p2);
}
Copyright © 2003 Xavax Inc. -- All Rights Reserved