On Thursday 06 February 2003 16.17, Martijn Sipkema wrote:
[...classes with private stuff hidden...]
It doesn't work that way. You cannot create an
class instance
without its full declaration. I don't see the problem of having the
private part of a class in the header. If you want to be seperated
from the implementation, use an abstract class. But then you cannot
create a class instance, you can only use the provided interface on
an already created instance (, but you can delete it when there is
a virtual destructor in the interface).
BTW, notice the similarity with C? If you don't know *every* detail of
a struct, you can't create an instance of one, because you don't know
it's *size*. The 'new' operator of C++ (and "static" instances for
that matter) have exactly the same problem, which is why things are
the way they are.
So, the basic problem is that it's not the constructor that allocates
memory for the instance; it's the code generated by the 'new'
operator.
There are ways around this, of course. For example, you can "wrap" the
constructor of a class in a static member of the class, that performs
the instantiation and returns a pointer. The "fake" constructor would
actually give you an instance of a "secret" derived class that
contains the implementation.
BTW, I believe this is about the way normal constructors work in
Delpih/Object Pascal - which is why you cannot have static instances
at all. No matter what you type, what you get is always a pointer.
note that the
private stuff would be in a file that looked just
like the class declaration, but had no public (and protected?)
declarations. in other words, the class declaration it includes
is implicitly 100% private, but it can include header files that
are necessary for the private declarations.
I don't see what this would solve and I don't think this is even
possible. Changing the private part will break binary compatibility
(without changing the public header).
Exactly. I've explained the reason why it's impossible above.
//David Olofson - Programmer, Composer, Open Source Advocate
.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`--------------------------->
http://olofson.net/audiality -'
---
http://olofson.net ---
http://www.reologica.se ---