constructor <class name> and <class name>()

constructor <class name> and <class name>()

Post by balisto leborgn » Fri, 04 Jan 2002 23:25:03



hi all,
i quote a difference between the calls of constructors <class name> and
<class name>()...

for exemple, if i use this kind of class:
class MyClass{
        int data;
    public:
        MyClass( int pData = 0){ data = pData;}

Quote:};

then, i declare:
MyClass    Obj1;
MyClass    Obj2( 5);
MyClass    Obj3();

I realized that Obj1 and Obj2 call the defined constructor, but Obj3 is an
empty instance and calls no constructor...
It appears to be strange for me, as i believed the Obj3 would call my
constructor.

Can you explain me that. Maybe there was something i didn't understand...

thanks
-nicoV-

PS: i'm using a borland 5.02 IDE

 
 
 

constructor <class name> and <class name>()

Post by Jon Bill » Fri, 04 Jan 2002 23:36:45



Quote:> hi all,
> i quote a difference between the calls of constructors <class name> and
> <class name>()...

> for exemple, if i use this kind of class:
> class MyClass{
>         int data;
>     public:
>         MyClass( int pData = 0){ data = pData;}
> };

> then, i declare:
> MyClass    Obj1;
> MyClass    Obj2( 5);
> MyClass    Obj3();

> I realized that Obj1 and Obj2 call the defined constructor, but Obj3 is an
> empty instance and calls no constructor...
> It appears to be strange for me, as i believed the Obj3 would call my
> constructor.

> Can you explain me that. Maybe there was something i didn't understand...

Obj3 is *not* an object, it's a function declaration.

See the FAQ, item 10.2: http://www.parashift.com/c++-faq-lite/.

Jon.

--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG

 
 
 

constructor <class name> and <class name>()

Post by Karl Heinz Buchegge » Sat, 05 Jan 2002 00:04:00



> MyClass    Obj1;
> MyClass    Obj2( 5);
> MyClass    Obj3();

:-)
The last line says:
Obj3 is a function, taking no arguments and returning
a MyClass object.
It's not a definition of a variable, instead it is
a function prototype.

--
Karl Heinz Buchegger

 
 
 

constructor <class name> and <class name>()

Post by balisto leborgn » Sat, 05 Jan 2002 00:52:50


ok, thanks, i see... :))
 
 
 

1. HELP >>>>>>>>>>>>> WINAPI <<<<<<<<<<<<<<<<<

   I need help in writting a vb program that will monitor the message
queue of another aplication that is running along with my program. Itried
to use PeekMessage api function but the help file says that it can only
peek the application's own message queue.  My program is similar in
working with SPY or the SPY++ program. Is there an api function that Ican
use. PLEEEEEEEEEZE help.

2. hyperlink postpack

3. <<<<<<Programmers Needed>>>>>>>

4. Permission problem NT domain, smb.conf

5. >>>>>>>>> PROBLEM WITH MSICPB.EXE <<<<<<<<<<<<<<<<<

6. Sun suppliers in St. Louis, Missouri?

7. <<>><><><><><><><><><><>

8. Tin & changi posting problem

9. <><><> www.FotoCD.net <><><>

10. ************************<<<<<<LOTUS CORP.SUCKS>>>>>*****************

11. >>>>>STUCK<<<<<< How to subclass desktop?

12. >>>>> SoftImage Animator - North West UK <<<<<<