D newb

BCS ao at pathlink.com
Sun Aug 17 16:36:53 PDT 2008


Reply to Tim,

> BCS Wrote:
> 
>> Reply to Tim,
>> 
>>> Hi, I am a D newbie.  Why does this program segfault?
>>> 
>>> import std.stdio;
>>> import std.c.stdlib;
>>> class Foo
>>> {
>>> public int m_int = 0;
>>> }
>>> int
>>> main(string[] args)
>>> {
>>> Foo f;
>>> printf("foo %d\n", f.m_int);
>>> return EXIT_SUCCESS;
>>> }
>> The default value for any object Reference (f in this case) is null.
>> create a new object to use (Foo f = new F();)
>> 
> Doh, can you guess what language I am coming from? :)
> 
> Is there any way to do C++ style on-stack local object ?
> 

"scope" look it up in the classes spec page (I have not used it myself)





More information about the Digitalmars-d mailing list