Thread: Can objects be used as built-ins?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    48

    [SOLVED] Can objects be used as built-ins?

    I'm wondering if and how to make a class return an integer without calling a member function.

    Example

    Code:
    int bar (int a); 
    
    int main()
    {
      Foo f(); // create a Foo object
    
      // Example A
      int a;
    
      a = f + 1; // Treat f as an int
    
      // Example B
      a = bar(f); // Treat f as an int
    
      // Example C
      return f; // Treat f as an int
    }
    Example A can be done with operator overloading. But what about B and C?


    I want to do this so I can make a class, FifoPtr, that behaves exactly like an int except when assigning a new value to it, it does a (% size) before assigning. I'd like to do it without having to call Foo::get_val() or something in examples B and C.

    Any ideas?
    Last edited by BdON003; 09-10-2011 at 12:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 05-24-2011, 06:36 PM
  2. built-in methods
    By Aisthesis in forum C++ Programming
    Replies: 10
    Last Post: 12-22-2009, 11:07 PM
  3. Built date
    By groorj in forum C Programming
    Replies: 2
    Last Post: 06-08-2005, 09:04 AM
  4. Just built my PC for college
    By Waldo2k2 in forum Tech Board
    Replies: 6
    Last Post: 10-30-2003, 11:28 AM
  5. Replies: 4
    Last Post: 10-16-2003, 11:26 AM