Results 1 to 8 of 8

Thread: passing the input right through to the function

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    183

    passing the input right through to the function

    I may be just experiencing a moment of stupidity, but is there a way to pass input from the keyboard right through to a function without putting it first in a variable?
    normally I would go
    cin>>var_1;
    function(var_1);

    what I would rather do though is something like
    cin >> function;

    any ideas??

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Unless the function is overloaded you could overload the istream operator >> for function pointers, but i'm not enteriely sure if it's possible.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    you could use the C stdio functions. They have the input as return values.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Zaei
    Guest
    Interesting. This works...
    Code:
    typedef VOID f(int x);
    operator >> (istream_withassign lhs, f* rhs)
    {
          int x;
          lhs >> x;
          f(x);
    }
    
    VOID foo(int x)
    {
        cout << x * x;
    }
    
    int main
    {
       cin >> foo;
       return 0;
    }
    Z.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Really???
    I would have said that the typedef instruction can't be compiled.
    This is a very atypical function pointer declaration. I would have used
    typedef void (*pf)(int);
    and pf as argument type of the operator overload...
    Strange...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    jim mcnamara
    Guest
    stdio -

    getch()
    getche()
    getc()

    using stdin - this work for you?

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Originally posted by Zaei

    Besides, a pointer should tell you it's a pointer. So, had I typedefed the way you said, It would have been a "LPf" =).
    Yeah, I wrote pf.
    lp is a relict from 16-bit programming when there were near (16-bit) pointers and far (32-bit) pointers. (or something like that).
    the l stands for long and means a far pointer. In 32-bit enviroment, all pointers are 32-bit.
    I still think it's interesting that you can give a function type a name and not only function pointer types.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8
    Zaei
    Guest
    Yeah, I am still running DOS on my laptop, so i get to worry about near and far pointers =). Ive never actually tried to pass a typedef int f(); to a function. I wonder if it would work...

    Z.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width