C
Christian Christmann
Hi,
reading the output of gprof for one of my projects, I found that the
STL list assignment operator consumes a larger fraction of the
program's execution time. The exact entry in gprof's output looks
as follows:
std::list<MyClass*, std::allocator<MyClass*> >:
perator=
(std::list<MyClass*, std::allocator<MyClass*> > const&) >
Since I don't know the source code for STL lists, I assume that
calling the assignment operator means that for each element
of the STL list the element's assignment operator is called. If
this is right, I don't understand why this works at all since I
explicitly disallow copying of MyClass objects by defining its
assignment operator private:
class MyClass:
private:
MyClass& operator=( const& MyClass );
So, the compiler does not create an default assignment operator
automatically. Thus, IMHO, STL list's operator= should fail.
Any ideas why this still works?
Regards,
Chris
reading the output of gprof for one of my projects, I found that the
STL list assignment operator consumes a larger fraction of the
program's execution time. The exact entry in gprof's output looks
as follows:
std::list<MyClass*, std::allocator<MyClass*> >:
(std::list<MyClass*, std::allocator<MyClass*> > const&) >
Since I don't know the source code for STL lists, I assume that
calling the assignment operator means that for each element
of the STL list the element's assignment operator is called. If
this is right, I don't understand why this works at all since I
explicitly disallow copying of MyClass objects by defining its
assignment operator private:
class MyClass:
private:
MyClass& operator=( const& MyClass );
So, the compiler does not create an default assignment operator
automatically. Thus, IMHO, STL list's operator= should fail.
Any ideas why this still works?
Regards,
Chris