mo********@yahoo.com wrote:
In a recent discussion, some of us were in disagreement about the
functions the C++ compiler generates. How many functions are generated
by the compiler when you declare:
class Foo
{
}; ?
I thought 4. As in:
class Foo
{
public:
Foo(); // default constructor
Foo(const Foo& f); // default copy constructor
This is called "a copy constructor", not "default copy constructor"
~Foo(); // default destructor
There is no such thing as a "default destructor". There is always
only one destructor.
Foo &operator(const Foo& f); // default assigment operator
Probably just a typo. Should be:
Foo &operator=(const Foo& f);
And this is actually called "copy assignment operator".
};
Is this list correct? Is that all?
Yes. Yes.
Someone said you must also add the new and delete operators, so that's
6. I have not read the standard, but I'd argue that if this is so,
then you should also count operator* () and operator& ()
There is no "default" operator* for a class. If the class doesn't
define its own 'new' and 'delete', the global ones are used. Also,
there is no action you can take to make compiler omit those, so we
usually don't count them. You *can* do something to make compiler not
to generate a default c-tor, a copy-c-tor, or a copy-assignment-op.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask