Access violation when using classes (beginner)

Johan Granberg lijat.meREM at OVE.gmail.com
Fri Jan 5 20:52:56 PST 2007


Robin Allen wrote:

> Hi, could someone tell me why this code gives an access violation? It
> seems I must be missing some fundamental difference between C++ and D.
> 
> class C
> {
>     void zing() {}
> }
> 
> void main()
> {
>     C c;
>     c.zing();
> }

Yes :)

classes are reference types so the current value of c is null. To initialize
c change "C c;" into "C c=new C()".


More information about the Digitalmars-d-learn mailing list