Re: Private constructor

From: Ron Natalie (ron_at_sensor.com)
Date: 12/20/03


Date: Sat, 20 Dec 2003 10:37:07 -0500


"Andy" <garth_rockett@yahoo.com> wrote in message
news:96dbbc80.0312200331.5098622c@posting.google.com...
> <
> I am sorry I made a stupid mistake. I was under the impression that
> just as static functions cannot access instance data members of a
> class, they also cannot call non-static member functions. Of course
> member functions are not per instance even if they are made to look
> that way. Constructor being a special kind of such a function should
> be accessible from static member functions.
> >
>
> That was stupider on second thoughts. A constructor does not get a
> this pointer secretly. So it's not a special kind of the others ... it
> is special and different from the rest. Nevertheless, I think I am
> right in assuming that neither the member functions nor the
> constructor or destructor constitute the state of an instantiated
> object - therefore static member functions should be able to access
> them

I have no clue what you are talking about. Constructors are non-static
member functions. You can't call them. They do have this pointers.
You're confusing access with instantiation. A static member function
has access to the private members of other objects of the same class
just like non-static members of one object can access private
members of other instances of the class.



Relevant Pages

  • [Nit] Re: Private constructor
    ... >>I am sorry I made a stupid mistake. ... Constructor being a special kind of such a function should ... >>be accessible from static member functions. ...
    (comp.lang.cpp)
  • Re: *this* keyword
    ... "The this keyword refers to the current instance of the class. ... Static member functions do not have a this pointer. ... In C++, it was generally more acceptable to prefix member access w/ this->, mostly because C++ is a hodge-podge of a language with both classes and functional roots. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Shared classes or modules?
    ... initialization code that is executed the very first time you use any member ... I could have the Sub New above open the log file the first time I went ... Other posts say that a module have no default constructor but it can ... >> Also you should make the constructor private, to prevent instantiating ...
    (microsoft.public.dotnet.languages.vb)
  • Re: C++ 101 dumb question
    ... Its action is to copy the data members of the class, ... If one of those members is a pointer, ... have it's own copy constructor would the default copy constructor call ... as a copy of the class being returned is placed on the stack for the ...
    (microsoft.public.vc.language)
  • Re: Error using ==> class
    ... The argv in there is obviously a holdover. ... varargin because varargin apparently does not actually allow nargin == ... the change, no changes to code are made, and the constructor (as seen ... All instances of an object must have the same member names in the same ...
    (comp.soft-sys.matlab)