acehreli
10/23/2008 9:35:00 PM
On Oct 23, 2:09 pm, tonytech08 <tonytec...@gmail.com> wrote:
> On Oct 23, 12:44 pm, acehr...@gmail.com wrote:> On Oct 23, 10:38 am, tonytech08 <tonytec...@gmail.com> wrote:
> > MyType m;
>
> > I read the Design and Evolution of C++ a long time ago but don't
> > remember registering anything like that.
>
> "Behaving like built-in type" means much more than "MyType m;"
> example. Think about the following group of special "things" in a
> class implemented to behave like a built-in type: default constructor,
> copy constructor, assignment operator, destructor.
Because of some of those, classes are better than built-in types.
That's part of the reasons why built-in types are referred to as
"second class" types:
- default constructor: missing for built-in types
- assignment operator: not always what we want for built-in types
- destructor: empty for built-in types; not always what we want
> Think about what
> happens when you pass an object by value as a function argument.
> Somehow, you have to handle potential errors from the copy
> constructor. Solution: exceptions.
Yes, exceptions are a mechanism of handling errors. The alternative of
handing error codes from layer to layer is not better.
They are not for built-in type behavior.
> So more machinery than just exception to get built-in-type behavior:
> default constructor, copy constructor, assignment operator,
> destructor, compiler machinery to call these member functions. Is it
> built-in-type behavior that lucrative to be worth all that?
They are all very important features without any connection to trying
to be like built-in types. Those are basic operations on types that we
need. The reason that built-in types have those operations is because
they are fundamental operations.
If those features are not important enough, one could always use C for
a while and come back to C++. ;)
Ali