> Hi
>
> Is this a bug? I don't know what's wrong with the code...
>
> //////////////code starts//////////
>
> #include <iostream>
> using namespace std ;
>
> // define a class
> class myclass
> {
> int i ;
> public:
> myclass(int n) ;
> ~myclass() ;
> void set_i(int n) { i = n ;}
> int get_i() { return i ; }
> };
>
> // constructor
> myclass::myclass(int n)
> {
> i=n ;
> cout << "\nConstructing " << i ;
> }
>
> // destructor
> myclass::~myclass()
> {
> cout << "\nDestroying " << i ;
> }
>
> // global function
> void f(myclass ob) ;
>
> int main()
> {
> myclass o(1) ; // constructor for o called here
>
> f(o) ;
> // pass object by val, bitwise copy of object done
>
> cout << "\nThis is i in main: " ;
> cout << o.get_i() ;
>
> return 0 ; // destructor for o
> }
>
> void f(myclass ob)
> {
> ob.set_i(2) ;
>
> cout << "\nThis is i in f(): " << ob.get_i() ;
> }
>
> //destructor for ob
>
> /////////////////code ends/////////////
>
> but the output is...
>
> Constructing 1
> This is i in f(): 2
> Destroying 2
> Destroying 1
> This is i in main: 1
> Destroying 1
>
> the output is proper in TurboC++:
>
> Constructing 1
> This is i in f(): 2
> Destroying 2
> This is i in main: 1
> Destroying 1
>
> Anything I am missing? I think its a bug.
>
> Shashi
> sha...@ie...
> --------------------------------------------------------------------------
--
> ----------------------------------
> My child, what I want is muscles of iron and nerves of steel,
> inside which dwells a mind of the same material as that of which
> the thunderbolt is made.
> -Swami Vivekananda
> --------------------------------------------------------------------------
--
> ----------------------------------
>
>
>
|