digitalmars.D.learn - struct opCall error messages
- Rory Mcguire (24/24) Jul 26 2010 Hi,
- Jacob Carlborg (7/31) Jul 27 2010 Perhaps you want a static opCall ?
- Rory Mcguire (3/41) Jul 28 2010 doh! [slaps head]
Hi, I'm not sure this is in bugzilla, I tried finding something mentioning it but coudn't. Compiling the below code results in the dmd compiler printing: struct_bad_error.d(8): Error: 'this' is only defined in non-static member functions, not inner ==================== struct S { S opCall() {S s; return s;} } void main() { S s; //s = S(); // decent error message: "struct_bad_error.d(6): // Error: need 'this' to access member opCall" void inner() { s = S(); } } ===================== What to do? Also found that having an empty () after the struct name is not the best error message: "struct_bad_error.d(5): Error: struct struct_bad_error.S() is used as a type" Surely it could tell me I need to put an Identifier in the () -Rory
Jul 26 2010
On 2010-07-26 14:27, Rory Mcguire wrote:Hi, I'm not sure this is in bugzilla, I tried finding something mentioning it but coudn't. Compiling the below code results in the dmd compiler printing: struct_bad_error.d(8): Error: 'this' is only defined in non-static member functions, not inner ==================== struct S { S opCall() {S s; return s;} } void main() { S s; //s = S(); // decent error message: "struct_bad_error.d(6): // Error: need 'this' to access member opCall" void inner() { s = S(); } } ===================== What to do? Also found that having an empty () after the struct name is not the best error message: "struct_bad_error.d(5): Error: struct struct_bad_error.S() is used as a type" Surely it could tell me I need to put an Identifier in the () -RoryPerhaps you want a static opCall ? S foo; foo(); // calls opCall S(); // calls static opCall -- /Jacob Carlborg
Jul 27 2010
Jacob Carlborg wrote:On 2010-07-26 14:27, Rory Mcguire wrote:doh! [slaps head] ThanksHi, I'm not sure this is in bugzilla, I tried finding something mentioning it but coudn't. Compiling the below code results in the dmd compiler printing: struct_bad_error.d(8): Error: 'this' is only defined in non-static member functions, not inner ==================== struct S { S opCall() {S s; return s;} } void main() { S s; //s = S(); // decent error message: "struct_bad_error.d(6): // Error: need 'this' to access member opCall" void inner() { s = S(); } } ===================== What to do? Also found that having an empty () after the struct name is not the best error message: "struct_bad_error.d(5): Error: struct struct_bad_error.S() is used as a type" Surely it could tell me I need to put an Identifier in the () -RoryPerhaps you want a static opCall ? S foo; foo(); // calls opCall S(); // calls static opCall
Jul 28 2010