|
/** @file underload.cpp
@brief A way to make overload using just the return type.
@author Wanderley Caloni
*/
#include <windows.h>
#include <objbase.h>
#include <tchar.h>
#include <iostream>
#include <string>
using namespace std;
struct CreateNewGUID
{
operator wstring () // the first function...
{
GUID guid = operator GUID();
OLECHAR buf[40] = { };
::StringFromGUID2(guid, buf, sizeof(buf));
return wstring(buf);
}
operator GUID () // ... and its "underload"
{
GUID guid = { };
::CoCreateGuid(&guid);
return guid;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
wstring guidS;
GUID guid;
// instanciates a CreateNewGUID e calls CreateNewGUID::operator wstring()
guidS = CreateNewGUID();
// instanciates a CreateNewGUID e calls CreateNewGUID::operator GUID()
guid = CreateNewGUID();
wcout << L"Just to print something:\\n"
<< guidS << L'\n';
return 0;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.