devxlogo

Use User-defined Where Built-in Is Expected

Use User-defined Where Built-in Is Expected

Say you’ve got a function that takes some built-in kind of parameter. You need to make that function work?even for an object (which has a data member of that built-in type type)?all without changing the syntax of your function call statement. This code can do it for you:

class INT{public:   INT( int t): y(t)   {}  operator int ()  {    return y;  }private: int y;};void func (int y){  cout << y;}int main (){  int t = 9;  func(t);  INT obj_INT(6);  func(obj_INT);}
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist