A
Alex Blekhman
Hello,
I'm using VC6.0 SP6 on Win2K machine. I have strange behaviour of
exception handling mechanism. Here's small example that exposes the
issue:
-------
class X
{
public:
X()
{ _tprintf(_T("X::X(); 0x%p\n"), this); }
X(const X& other)
{ _tprintf(_T("copy; 0x%p = 0x%p\n"), this, &other); }
~X()
{ _tprintf(_T("~X::X(); 0x%p\n"), this); }
};
int _tmain(int argc, _TCHAR* argv[])
{
try
{
_putts(_T("before"));
throw X();
}
catch(X& x)
{
_putts(_T("catch"));
}
_putts(_T("after"));
return 0;
}
-------
It produces correct output:
-------
before
X::X(); 0x0012FF68
catch
~X::X(); 0x0012FF68
after
-------
Now, if I remove copy constructor and build and run it, then output
is:
-------
before
X::X(); 0x0012FF64
~X::X(); 0x0012FF64
catch
~X::X(); 0x0012FF68
after
-------
As you can see default copy constructor was created by compiler and
actually called. My question is: Why copy constructor is not called
when I explicitly provide it, but called when auto generated by
compiler?
Thanks in advance
Alex
I'm using VC6.0 SP6 on Win2K machine. I have strange behaviour of
exception handling mechanism. Here's small example that exposes the
issue:
-------
class X
{
public:
X()
{ _tprintf(_T("X::X(); 0x%p\n"), this); }
X(const X& other)
{ _tprintf(_T("copy; 0x%p = 0x%p\n"), this, &other); }
~X()
{ _tprintf(_T("~X::X(); 0x%p\n"), this); }
};
int _tmain(int argc, _TCHAR* argv[])
{
try
{
_putts(_T("before"));
throw X();
}
catch(X& x)
{
_putts(_T("catch"));
}
_putts(_T("after"));
return 0;
}
-------
It produces correct output:
-------
before
X::X(); 0x0012FF68
catch
~X::X(); 0x0012FF68
after
-------
Now, if I remove copy constructor and build and run it, then output
is:
-------
before
X::X(); 0x0012FF64
~X::X(); 0x0012FF64
catch
~X::X(); 0x0012FF68
after
-------
As you can see default copy constructor was created by compiler and
actually called. My question is: Why copy constructor is not called
when I explicitly provide it, but called when auto generated by
compiler?
Thanks in advance
Alex