P
Paul Drummond
Hi,
I hope I am not posting in the wrong place! I have posted to the MFC
group but thought I might get more of a response here as the question
is C++ specific. If I am wrong to post here or violating some rule
please let me know and I promise I won't do it again
I am using MFC/COM _bstr_t() in Visual C++ 6.0 and I am insterested to
know what constructors get called when the following call is made:
int main()
{
_bstr_t b = _bstr_t("Hello world");
return 0;
}
I realise VC++ is old and not standards-compliant, so forgetting that
for a moment I just want to make sure what I think should happen is
what would happen in ANSI C++!
I would expect the constructor which accepts a const char* would be
called which would return a temporary object then the copy-constructor
would be called to assign the temporary to "b".
When I run the debugger, the const char* constructor is called but no
copy-constructor! At first I thought this may be a compiler
optimization of some sort, or maybe some obsure feature of Visual C++
6.0 so I made a dummy class to test my theory and I was correct - the
copy constructor is called for my test class, so why not for _bstr_t?
I hope I am not posting in the wrong place! I have posted to the MFC
group but thought I might get more of a response here as the question
is C++ specific. If I am wrong to post here or violating some rule
please let me know and I promise I won't do it again
I am using MFC/COM _bstr_t() in Visual C++ 6.0 and I am insterested to
know what constructors get called when the following call is made:
int main()
{
_bstr_t b = _bstr_t("Hello world");
return 0;
}
I realise VC++ is old and not standards-compliant, so forgetting that
for a moment I just want to make sure what I think should happen is
what would happen in ANSI C++!
I would expect the constructor which accepts a const char* would be
called which would return a temporary object then the copy-constructor
would be called to assign the temporary to "b".
When I run the debugger, the const char* constructor is called but no
copy-constructor! At first I thought this may be a compiler
optimization of some sort, or maybe some obsure feature of Visual C++
6.0 so I made a dummy class to test my theory and I was correct - the
copy constructor is called for my test class, so why not for _bstr_t?