Mail Archives: djgpp/2001/01/18/10:04:27
Rafal Maj <maj_rafal AT poczta DOT onet DOT pl> wrote:
> Hi,
> how to create object of my class "Class" using new, so this object will be
> placed in some allocated before memory area ?
You don't. Or, at least: you shouldn't be trying to do that.
Having two pointers of different type point to the same object will
most likely cause nothing but all kinds of headaches, in the long run.
If you really think you absolutely have to do this: don't allocate the
other pointer before you allocate the object. Then you can cast the
object pointer to the first one's type and assign it:
char *chunk = (char *) object_ptr;
or something more C++ish (C++ has other cast operators that are
claimed to be preferrable over the classic C style cast).
The problem with this idea is that it's almost completely undefined
what the contents of string 'chunk' will be, now. Just about
everything you do with it will cause undefined behaviour of your
program, or make invalid assumptions that will bite you, later.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -