Shahriyar
Shahriyar

Reputation: 1583

C++ Make a class to act as a specific data type

In MFC I see it's possible to pass CStringA/CStringW to functions that get CHAR*/WCHAR*

So for example how it is possible to create a class to act as unsigned char* or int for the functions that get unsigned char* or int as argument ?

Upvotes: 0

Views: 80

Answers (1)

Wojtek Surowka
Wojtek Surowka

Reputation: 20993

You need to create some means of automatic conversion of your class to the type you need. The easiest way is to create a cast operator, e.g.:

operator int()
{
   ...
   return <the int value based of your object>;
}

Upvotes: 2

Related Questions