devxlogo

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);}

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

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.