[linux-audio-dev] (OT) C++ flame war

Martijn Sipkema msipkema at sipkema-digital.com
Wed Feb 5 19:14:01 UTC 2003


[...]
> for an on-topic rant, see Erik de Castro Lopo's interview on mstation.org:
>
>   http://mstation.org/erikdecl.php
>
> where he discusses the OO design of libsndfile and libsamplerate
> (surely two of the most rock-solid audio libraries ever!)

>From this article:

"I also think that there is a real problem with the way classes are defined
in C++ and this is a problem which really does impact design. The problem is
that you are forced to define the private data members and functions at the
same time as the public ones. This is OK for the trivial C++ examples you
see in textbooks but as soon as you REALLY want to hide the private
information you end up defining the class to have a single private void
pointer which gets something allocated to it in the implementation. This is
basically the same thing you do when doing OO programming in C, so where is
the benefit of C++?"

--

You are not forced to define the private data members and functions at the
same time as
the public ones in C++. The way to handle this is to put the public
interface in a pure
virtual class:

class animal
{
public:
    virtual int legs() = 0; // returns number of legs the animal uses when
moving around
};

and then derive from that interface:

class dog : public animal
{
public:
    int legs() { return 4; }
};


I think most of the arguments in the article are not valid, but I guess I
really shouldn't
be making my point here on this list.

It can't hurt for to also hear some positive comments on C++ occasionally
though...

--ms







More information about the Linux-audio-dev mailing list