In D, I created a class called MyClass with a sub-class called Data. In main, I created an instance of MyClass. There're two problems with my code: 1) Cannot access the member of the sub-class. 2) Cannot use the constructor when the instance to MyClass is created.
class MyClass
{
public:
this( int Init = 0 )
{
IntMember = Init;
}
class Data
{
int Member = 0;
}
int Variable = 0;
protected:
int IntMember = 0;
}
int main( )
{
MyClass Class( 4 ); // Error 1) no property 'opCall' for type 'hello.MyClass'
Class.Variable = 9; // This is fine.
Class.Data.Member = 5; // Error 2) 'this' is only defined in non-static member functions, not main
return 0;
}
Error: 1
I've tried removing the parentheses from round the constructor and it removes the error. So how do I use the defined constructor in MyClass?
Error: 2
I've tried using the this keyword but give me the same error.