www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Calling method on new instance of class

reply pmoore <pmoore_member pathlink.com> writes:
Hi,

Sorry if I'm labouring an old point but is there a reason why I can't do the
following:

class A {
public this() {}
public void doSomething() {}
}

int main() {
new A().doSomething(); // can't do this
}

Thanks.
Jun 17 2005
parent reply xs0 <xs0 xs0.com> writes:
pmoore wrote:
 Hi,
 
 Sorry if I'm labouring an old point but is there a reason why I can't do the
 following:
 
 class A {
 public this() {}
 public void doSomething() {}
 }
 
 int main() {
 new A().doSomething(); // can't do this
 }
 
 Thanks.

You can, it's just a precedence problem: (new A()).doSomething() xs0
Jun 17 2005
parent pmoore <pmoore_member pathlink.com> writes:
Ah. Thank you.

In article <d8ugjo$19e3$1 digitaldaemon.com>, xs0 says...
pmoore wrote:
 Hi,
 
 Sorry if I'm labouring an old point but is there a reason why I can't do the
 following:
 
 class A {
 public this() {}
 public void doSomething() {}
 }
 
 int main() {
 new A().doSomething(); // can't do this
 }
 
 Thanks.

You can, it's just a precedence problem: (new A()).doSomething() xs0

Jun 17 2005