Mail Archives: djgpp/2000/02/29/13:53:57
Florian X <dos DOT fire AT aon DOT at> wrote:
> If I use NULL in c++, the compiler prints me this error:
You forgot to show us *how* you use NULL, in your program. That's an
important detail you're hiding from us.
> dc.cc:167: ANSI C++ forbids implicit conversion from `void *' in argument
> passing
The error message says it all, I think. Unlike C, C++ does not allow
to use a 'void *' expression (like NULL) where a pointer to some
specific type is requested. In C, you can do that, as the 'void *'
will automatically be casted to the right type. That's the 'implicit
conversion' the error message speaks of. In C++, you have to write
down the cast, in the source code. The typical example:
some_type *p = malloc(number*sizeof(some_type));
does not work in C++, although it is perfectly valid C. In C++, you
have to write the following, instead:
some_type *p = (some_type*) malloc(number*sizeof(some_type));
(Or use one of the specialized cast operators offered by C++, like
'static_cast')
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -