GUID default value in c++
I want to use a GUID in my class.
1) I want to give it a default value in the default开发者_高级运维 constructor (something like 0, NULL, etc). How can I do it?
2) In another constructor, I want to give it a default value in a case the call for the constructor don't have it. for example:
the constructor: MY_CLASS(int a, int b, int c = 0, GUID g = ???)
the call: MY_CLASS m = new MY_CLASS(5,3);
How can i do it?
Thanks
1, Default value of a GUID: GUID_NULL
, or IID_NULL
(it is alias of GUID_NULL
)
2, I think you should use REFGUID rather than GUID directly. In the header files you can use DEFINE_GUID(guid_name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
to define the static GUID guid_name. In your Class define a REFGUID member and assign the guid_name to it.
// {4CAD5FED-86CA-453a-B813-0876DAA992DF}
DEFINE_GUID(_guid_A,
0x4cad5fed, 0x86ca, 0x453a, 0xb8, 0x13, 0x8, 0x76, 0xda, 0xa9, 0x92, 0xdf);
class MyClass {
private:
REFGUID rguid;
public:
MyClass() : rguid(&GUID_NULL)
{ }
MyClass(int a) : rguid(&_guid_A)
{ }
};
精彩评论