www.digitalmars.com         C & C++   DMDScript  

D - class construction bug?

reply Sean Kelly <sean ffwd.cx> writes:
I just tried this:

class A
{
protected:
     this() { printf( "ctor\n" ); }
}

int main()
{
     A a = new A();
}

And it compiled and, when run, printed: "ctor."  Is the "protected" 
keyword not working correctly or is there some rule that class 
constructors are inherently public?


Sean
Feb 24 2004
parent reply "Kris" <someidiot earthlink.net> writes:
Attributes are apparently applied at the module-level, rather than the
class-level.


"Sean Kelly" <sean ffwd.cx> wrote in message
news:c1ga1h$1c3d$1 digitaldaemon.com...
 I just tried this:

 class A
 {
 protected:
      this() { printf( "ctor\n" ); }
 }

 int main()
 {
      A a = new A();
 }

 And it compiled and, when run, printed: "ctor."  Is the "protected"
 keyword not working correctly or is there some rule that class
 constructors are inherently public?


 Sean

Feb 24 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Kris wrote:

Attributes are apparently applied at the module-level, rather than the
class-level.

  

"Sean Kelly" <sean ffwd.cx> wrote in message
news:c1ga1h$1c3d$1 digitaldaemon.com...
  

I just tried this:

class A
{
protected:
     this() { printf( "ctor\n" ); }
}

int main()
{
     A a = new A();
}

And it compiled and, when run, printed: "ctor."  Is the "protected"
keyword not working correctly or is there some rule that class
constructors are inherently public?


Sean

    


-- -Anderson: http://badmama.com.au/~anderson/
Feb 24 2004
parent reply Sean Kelly <sean ffwd.cx> writes:
J Anderson wrote:
 That is not true in this situation.  Constructors are always public.

Hm. So how would I go about creating a singleton or other class that has special construction requirements? Sean
Feb 24 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Sean Kelly wrote:

 J Anderson wrote:

 That is not true in this situation.  Constructors are always public.

Hm. So how would I go about creating a singleton or other class that has special construction requirements? Sean

I'm not exactly sure what you mean by special construction requirements. There was a whole discussion on singletons before, so you might what to look at that (using module-level or static members were suggested). Search for singletons. -- -Anderson: http://badmama.com.au/~anderson/
Feb 24 2004
parent Sean Kelly <sean ffwd.cx> writes:
J Anderson wrote:
 
 I'm not exactly sure what you mean by special construction 
 requirements.  There was a whole discussion on singletons before, so you 
 might what to look at that (using module-level or static members were 
 suggested). Search for singletons.

Thanks. As for special construction requirements, I think that could all be handled by overloading "new." Just thinking out loud. Sean
Feb 24 2004