D - Class access problems
- Andrew Edwards (17/17) Jan 08 2003 The following class example taken from the documentation results in an
- Burton Radons (4/21) Jan 08 2003 a is initialised to null - you need to use "Abc a = new Abc;" to
- Andrew Edwards (6/27) Jan 08 2003 have get'ers and set'ers been implemented yet? Tried using them from the
- Burton Radons (3/28) Jan 08 2003 Wait, sorry, never mind. This excerpted code is not D, it's C++, so you...
- Andrew Edwards (21/49) Jan 08 2003 Here is the code as it originally appeared on the D website:
- Burton Radons (3/25) Jan 08 2003 Now this example IS a spec bug, as it's in D and doesn't initialise Abc.
The following class example taken from the documentation results in an Access violation error when compiled and executed under WinXP. Does anyone tell me what I'm doing wrong? class Abc { int myprop; int property(int newproperty) { myprop = newproperty; return 0;} // set'er int property() { return myprop; } // get'er } int main() { Abc a; a.property(3); int x = a.property(); return 0; } Thanks, Andrew
Jan 08 2003
Andrew Edwards wrote:The following class example taken from the documentation results in an Access violation error when compiled and executed under WinXP. Does anyone tell me what I'm doing wrong? class Abc { int myprop; int property(int newproperty) { myprop = newproperty; return 0;} // set'er int property() { return myprop; } // get'er } int main() { Abc a; a.property(3); int x = a.property(); return 0; }a is initialised to null - you need to use "Abc a = new Abc;" to initialise it to an instance. This is a spec bug - Walter, it's at (http://www.digitalmars.com/d/class.html) under the Fields section.
Jan 08 2003
have get'ers and set'ers been implemented yet? Tried using them from the original example but they don't seem to work "Burton Radons" <loth users.sourceforge.net> wrote in message news:aviak5$pe6$1 digitaldaemon.com...Andrew Edwards wrote:anyoneThe following class example taken from the documentation results in an Access violation error when compiled and executed under WinXP. Doesset'ertell me what I'm doing wrong? class Abc { int myprop; int property(int newproperty) { myprop = newproperty; return 0;} //int property() { return myprop; } // get'er } int main() { Abc a; a.property(3); int x = a.property(); return 0; }a is initialised to null - you need to use "Abc a = new Abc;" to initialise it to an instance. This is a spec bug - Walter, it's at (http://www.digitalmars.com/d/class.html) under the Fields section.
Jan 08 2003
Burton Radons wrote:Andrew Edwards wrote:Wait, sorry, never mind. This excerpted code is not D, it's C++, so you were trying it in the wrong language.The following class example taken from the documentation results in an Access violation error when compiled and executed under WinXP. Does anyone tell me what I'm doing wrong? class Abc { int myprop; int property(int newproperty) { myprop = newproperty; return 0;} // set'er int property() { return myprop; } // get'er } int main() { Abc a; a.property(3); int x = a.property(); return 0; }a is initialised to null - you need to use "Abc a = new Abc;" to initialise it to an instance. This is a spec bug - Walter, it's at (http://www.digitalmars.com/d/class.html) under the Fields section.
Jan 08 2003
Here is the code as it originally appeared on the D website: All this is quite a bit of typing, and it tends to make code unreadable by filling it with getProperty() and setProperty() calls. In D, get'ers and set'ers take advantage of the idea that an lvalue is a set'er, and an rvalue is a get'er: class Abc { int myprop; void property(int newproperty) { myprop = newproperty; } // set'er int property() { return myprop; } // get'er } which is used as: Abc a; a.property = 3; // equivalent to a.property(3) int x = a.property; // equivalent to int x = a.property() It does not work. So I had to modify it so that it works somehow. I hadn't noticed the C++ example above it. Thanks for pointing that out. The problem still remains though. This code does not work. Thanks, Andrew "Burton Radons" <loth users.sourceforge.net> wrote in message news:avic2o$qc6$1 digitaldaemon.com...Burton Radons wrote:Andrew Edwards wrote:Wait, sorry, never mind. This excerpted code is not D, it's C++, so you were trying it in the wrong language.The following class example taken from the documentation results in an Access violation error when compiled and executed under WinXP. Does anyone tell me what I'm doing wrong? class Abc { int myprop; int property(int newproperty) { myprop = newproperty; return 0;} // set'er int property() { return myprop; } // get'er } int main() { Abc a; a.property(3); int x = a.property(); return 0; }a is initialised to null - you need to use "Abc a = new Abc;" to initialise it to an instance. This is a spec bug - Walter, it's at (http://www.digitalmars.com/d/class.html) under the Fields section.
Jan 08 2003
Andrew Edwards wrote:Here is the code as it originally appeared on the D website: All this is quite a bit of typing, and it tends to make code unreadable by filling it with getProperty() and setProperty() calls. In D, get'ers and set'ers take advantage of the idea that an lvalue is a set'er, and an rvalue is a get'er: class Abc { int myprop; void property(int newproperty) { myprop = newproperty; } // set'er int property() { return myprop; } // get'er } which is used as: Abc a; a.property = 3; // equivalent to a.property(3) int x = a.property; // equivalent to int x = a.property() It does not work. So I had to modify it so that it works somehow. I hadn't noticed the C++ example above it. Thanks for pointing that out. The problem still remains though. This code does not work.Now this example IS a spec bug, as it's in D and doesn't initialise Abc. Anyway, as to your other question, properties aren't implemented in DMD yet.
Jan 08 2003