|
-
Sep 26th, 2001, 01:18 AM
#1
Thread Starter
Addicted Member
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??
-
Sep 26th, 2001, 03:34 AM
#2
transcendental analytic
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.
-
Sep 26th, 2001, 07:22 AM
#3
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.
-
Sep 26th, 2001, 07:36 AM
#4
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.
-
Sep 26th, 2001, 07:50 AM
#5
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.
-
Sep 26th, 2001, 10:50 AM
#6
stdio -
getch()
getche()
getc()
using stdin - this work for you?
-
Sep 27th, 2001, 09:32 AM
#7
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.
-
Sep 27th, 2001, 11:27 AM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|