Error: no property 'opCall' for type 'app1.ReturnContent'

Jonathan M Davis jmdavisProg at gmx.com
Wed Oct 24 03:29:29 PDT 2012


On Wednesday, October 24, 2012 12:00:11 Suliman wrote:
> import std.stdio;
> 
> void main()
> 
> {
> 	ReturnContent();
> }
> 
> 
> public class ReturnContent
> {
> 	void ReturnContent()
> 	{
> 		writeln("hello");
> 	}
> }
> 
> Why I am getting this error?
> D2

It means exactly what it says. ReturnContent is a class, so when you use 
ReturnContent(), you're trying to call the function operator on the type 
ReturnContent. That's not going to work unless you overloaded opCall on 
ReturnContent and made it static. e.g.

public class ReturnContent
{
    static void opCall()
    {
        writeln("static opCall");
    }
}

Your ReturnContent function inside of ReturnContent is only ever going to be 
callable on instances of ReturnContent, not on the type, so you must create an 
instance of it first. e.g.

auto rc = new ReturnContent;
rc.ReturnContent();

However, it's incredibly bizarre to name a member function the same name as 
the type. In D, constructors are named this, and member functions are most 
frequently named with camelCase - e.g. returnType - whereas types are most 
frequently named with PascalCase - e.g. ReturnType. So, naming a function the 
same as the type is odd and confusing.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list