digitalmars.D - Need a little help (probably being stupid)
- Dn7 (27/27) Jul 25 2004 I've downloaded the new D compiler to play with. However, I think I'm mi...
- Andrew Edwards (2/33) Jul 25 2004
- Dn7 (2/35) Jul 25 2004 Thanks :) That's so... JavaScriptish.
- Mike Parker (8/9) Jul 26 2004 It's also C++ish and Javaish. Whereas C++ allows you to create class
- J C Calvarese (9/38) Jul 25 2004 Try this:
- Andrew Edwards (6/51) Jul 25 2004 Quick question, which is the "correct" way?
- J C Calvarese (7/63) Jul 25 2004 If it works, I'd say it's right. :)
- Walter (3/8) Jul 26 2004 They're both correct. Use whichever!
I've downloaded the new D compiler to play with. However, I think I'm missing something important which I'm too blind for to see myself? It's about accessing class members, they throw access violation errors on both versions Direct and Indirect, even when Bar is public: // Small access violation example class Foo { public: int Bar; void setBar(int newvalue) { this.Bar = newvalue; printf("%i", this.Bar); } } void main() { Foo spawn; version(Direct) { printf("As though it was public: \n"); spawn.Bar = 2; printf("%i", spawn.Bar); } version(Indirect) { printf("As though it was private: \n"); spawn.setBar(1); } } Could someone point out where I'm being stupid? It's compiled with dmd test.d -version=Direct/Indirect -of test.exe...
Jul 25 2004
Dn7 wrote:I've downloaded the new D compiler to play with. However, I think I'm missing something important which I'm too blind for to see myself? It's about accessing class members, they throw access violation errors on both versions Direct and Indirect, even when Bar is public: // Small access violation example class Foo { public: int Bar; void setBar(int newvalue) { this.Bar = newvalue; printf("%i", this.Bar); } } void main() { Foo spawn;^------------ Foo spawn = new Foo;version(Direct) { printf("As though it was public: \n"); spawn.Bar = 2; printf("%i", spawn.Bar); } version(Indirect) { printf("As though it was private: \n"); spawn.setBar(1); } } Could someone point out where I'm being stupid? It's compiled with dmd test.d -version=Direct/Indirect -of test.exe...
Jul 25 2004
In article <ce0oak$2e4n$1 digitaldaemon.com>, Andrew Edwards says...Dn7 wrote:Thanks :) That's so... JavaScriptish.I've downloaded the new D compiler to play with. However, I think I'm missing something important which I'm too blind for to see myself? It's about accessing class members, they throw access violation errors on both versions Direct and Indirect, even when Bar is public: // Small access violation example class Foo { public: int Bar; void setBar(int newvalue) { this.Bar = newvalue; printf("%i", this.Bar); } } void main() { Foo spawn;^------------ Foo spawn = new Foo;version(Direct) { printf("As though it was public: \n"); spawn.Bar = 2; printf("%i", spawn.Bar); } version(Indirect) { printf("As though it was private: \n"); spawn.setBar(1); } } Could someone point out where I'm being stupid? It's compiled with dmd test.d -version=Direct/Indirect -of test.exe...
Jul 25 2004
Dn7 wrote:Thanks :) That's so... JavaScriptish.It's also C++ish and Javaish. Whereas C++ allows you to create class instances on the stack, D does not. All class instances must be created on the heap, and all class instance variables are references. Structs, on the other hand, may be instanced on the stack. So the following is okay: struct Foo { int bar; } Foo f; f.bar = 1;
Jul 26 2004
Dn7 wrote:I've downloaded the new D compiler to play with. However, I think I'm missing something important which I'm too blind for to see myself? It's about accessing class members, they throw access violation errors on both versions Direct and Indirect, even when Bar is public: // Small access violation example class Foo { public: int Bar; void setBar(int newvalue) { this.Bar = newvalue; printf("%i", this.Bar); } } void main() { Foo spawn;Try this: Foo spawn = new Foo(); More info: http://www.prowiki.org/wiki4d/wiki.cgi?ErrorMessages#Un-initializedObject http://www.prowiki.org/wiki4d/wiki.cgi?ShortFrequentAnswersversion(Direct) { printf("As though it was public: \n"); spawn.Bar = 2; printf("%i", spawn.Bar); } version(Indirect) { printf("As though it was private: \n"); spawn.setBar(1); } } Could someone point out where I'm being stupid? It's compiled with dmd test.d -version=Direct/Indirect -of test.exe...-- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Jul 25 2004
J C Calvarese wrote:Dn7 wrote:Quick question, which is the "correct" way? ... = new Foo; or ... = new Foo(); Just wondering because thy both work!I've downloaded the new D compiler to play with. However, I think I'm missing something important which I'm too blind for to see myself? It's about accessing class members, they throw access violation errors on both versions Direct and Indirect, even when Bar is public: // Small access violation example class Foo { public: int Bar; void setBar(int newvalue) { this.Bar = newvalue; printf("%i", this.Bar); } } void main() { Foo spawn;Try this: Foo spawn = new Foo();More info: http://www.prowiki.org/wiki4d/wiki.cgi?ErrorMessages#Un-initializedObject http://www.prowiki.org/wiki4d/wiki.cgi?ShortFrequentAnswersversion(Direct) { printf("As though it was public: \n"); spawn.Bar = 2; printf("%i", spawn.Bar); } version(Indirect) { printf("As though it was private: \n"); spawn.setBar(1); } } Could someone point out where I'm being stupid? It's compiled with dmd test.d -version=Direct/Indirect -of test.exe...
Jul 25 2004
Andrew Edwards wrote:J C Calvarese wrote:If it works, I'd say it's right. :) I usually see "Foo()" used, but apparently it doesn't matter if there are parentheses or not if it doesn't have any parameters.Dn7 wrote:Quick question, which is the "correct" way? .... = new Foo; or .... = new Foo(); Just wondering because thy both work!I've downloaded the new D compiler to play with. However, I think I'm missing something important which I'm too blind for to see myself? It's about accessing class members, they throw access violation errors on both versions Direct and Indirect, even when Bar is public: // Small access violation example class Foo { public: int Bar; void setBar(int newvalue) { this.Bar = newvalue; printf("%i", this.Bar); } } void main() { Foo spawn;Try this: Foo spawn = new Foo();-- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/More info: http://www.prowiki.org/wiki4d/wiki.cgi?ErrorMessages#Un-initializedObject http://www.prowiki.org/wiki4d/wiki.cgi?ShortFrequentAnswersversion(Direct) { printf("As though it was public: \n"); spawn.Bar = 2; printf("%i", spawn.Bar); } version(Indirect) { printf("As though it was private: \n"); spawn.setBar(1); } } Could someone point out where I'm being stupid? It's compiled with dmd test.d -version=Direct/Indirect -of test.exe...
Jul 25 2004
"Andrew Edwards" <ridimz_at yahoo.dot.com> wrote in message news:ce0olt$2ebj$1 digitaldaemon.com...Quick question, which is the "correct" way? ... = new Foo; or ... = new Foo(); Just wondering because thy both work!They're both correct. Use whichever!
Jul 26 2004