What will be printed on the screen?
#include <string>
#include <iostream>
using namespace std;
const wchar_t* g_testString = L"Hello, World";
wstring func()
{
    return wstring(g_testString);
}
int main()
{
    const wchar_t* wStr = func().c_str();
    if( wcscmp( wStr, g_testString ) == 0 )
    {
        cout<<"strings are equal";
        return 0;
    }
    cout<<"strings are not equal";
    return 0;
}
Explanation
Sometimes to reduce the code size, we create nameless temporary object of class.
When we want to return an object from member function of class without creating an object, for this: we just call the constructor of class and return it to calling function and there is an object to hold the reference returned by constructor.
This concept is known as nameless temporary objects, using this we are going to implement a C++ program for pre-increment operator overloading.
In gcc, the scope of the temporary nameless wstring object is defined by the function.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести