dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Intermediate
Apr 23, 2004

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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);
}
Saurabh Ramya
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date