Re: Problem with constructors

From: Peter MacMillan (peter_at_writeopen.com)
Date: 03/30/05


Date: Wed, 30 Mar 2005 02:24:02 -0500

darkstorm wrote:
> class A
> {
> public:
> void Fun();
> private:
> Vector2D vec;--------(A)
> };

This is just a definition of the class. When you instantiate the class
(eg. dynamically: A* a = ew A(); statically: A a;) it will create vec
and call it's constructor as part of the class initialization.

>
> void A::Fun()
> {
> Vector2D vec1;-------(B)
> .
> .
> .
> }

When your execution gets into that function, a Vector2D named vec1 is
created (and destroied at the end of the function).

>
> Here at (B) constructor for Vector2D is getting called, but at (A)
> constructor is not getting called. What can be the reason?
>
> Thanks

B is part of some code, A is part of a definition of a class.

-- 
Peter MacMillan
e-mail/msn: peter@writeopen.com	
icq: 1-874-927
GCS/IT/L d-(-)>-pu s():(-) a- C+++(++++)>$ UL>$ P++ L+ E-(-) W++(+++)>$ 
N o w++>$ O !M- V PS PE Y+ t++ 5 X R* tv- b++(+) DI D+(++)>$ G e++ h r-- 
y(--)


Relevant Pages

  • Re: DriverManager in JDBC
    ... constructor is private. ... because you are supposed to instantiate it with a factory. ...
    (comp.lang.java.programmer)
  • Re: DriverManager in JDBC
    ... because you are supposed to instantiate it with a factory. ... of its public methods returns a DriverManager. ... The effect of having a private constructor, ...
    (comp.lang.java.programmer)
  • Re: class inaccessible
    ... > private IntType ... "There are only two ways to instantiate an object of ... > accessible only from within the IntType class itself. ... > make at least one constructor "public". ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Private instance variables available everywhere within constructed object
    ...   var private; ...   function Constructor() ... instance's private variables, we can ensure that each instance has its ...
    (comp.lang.javascript)
  • Re: Deleting files modified before a specified number of days using Java.
    ... Not even able to create the fileArray object.... ... The class is doing too much work in the constructor - the constructor should only construct, ... // members should be private! ... public FileDeleter(String path, int days) ...
    (comp.lang.java.programmer)