www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - static opDispatch

reply David <d dav1d.de> writes:
struct Bla {
    static  property
	Bla opDispatch(string s)() const {
		pragma(msg, s);
		return Bla();
	}
}
		
void main() {
	Bla.abc;
}

---

abc
/d675/f256.d(10): Error: no property 'abc' for type 'Bla'
/d675/f256.d(10): Error: Bla is not an expression

---

I guess static opDispatch does not exist? Any reasons why it doesn't
exist or is it just a bug? It looks like a bug, since the pragma prints.
Returning nothing, doesn't change anything btw.
Jun 30 2013
parent reply Artur Skawina <art.08.09 gmail.com> writes:
On 06/30/13 12:36, David wrote:
 struct Bla {
     static  property
 	Bla opDispatch(string s)() const {
 		pragma(msg, s);
 		return Bla();
 	}
 }
 		
 void main() {
 	Bla.abc;
 }
 
 ---
 
 abc
 /d675/f256.d(10): Error: no property 'abc' for type 'Bla'
 /d675/f256.d(10): Error: Bla is not an expression
 
 ---
 
 I guess static opDispatch does not exist? Any reasons why it doesn't
 exist or is it just a bug? It looks like a bug, since the pragma prints.
 Returning nothing, doesn't change anything btw.
Try removing the 'const' - static methods have no 'this'. Error reporting for optional templated methods that exist, but fail to instantiate, can be very misleading; calling such methods explicitly sometimes helps to identify the problem. artur
Jun 30 2013
next sibling parent David <d dav1d.de> writes:
 Try removing the 'const' - static methods have no 'this'.
 
 Error reporting for optional templated methods that exist, but fail
 to instantiate, can be very misleading; calling such methods explicitly 
 sometimes helps to identify the problem.
 
 artur
 
Oh wow, so easy ... Thanks I tottally did not see that const.
Jun 30 2013
prev sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Artur Skawina:

 Error reporting for optional templated methods that exist, but 
 fail
 to instantiate, can be very misleading; calling such methods 
 explicitly
 sometimes helps to identify the problem.
http://d.puremagic.com/issues/show_bug.cgi?id=10511 Bye, bearophile
Jun 30 2013