|
-
March 4th, 2008, 12:49 AM
#6
Re: Function pointers...I don't know what they are
Hello spetsacdc,
I'm a beginner here, but like 7stud said, can't it be that you're leaving something out of the context?
because, you said if statement is now allowed (and I assume neither is switch), but you said a user is prompted to enter a choice, how is this possible without a condition?
Here's my best guess on what must be done.
1. both functions must give(not necessairly return) same End Result.
2. we need to create 5 seperate files. one for main.cpp, 2 for g.h/g.cpp, and 2 for f.h/f.cpp.
3. Let's assume "avoid two versions of the source code" as "One definition in one function is not seen in the other.
4. One of either function must accept a pointer as an ARGUMENT.
5. No conditional statements are allowed.
given all these, I believe (hopefully) either of the functions must call the other.
for instance; g.cpp would be something like
Code:
#include "g.h"
#include "f.h"
// pass by pointer
int g(int* y)
{
return f(*y);
}
and f.cpp
Code:
// pass by value
int f(int y)
{
int twice(0);
twice = y * 2;
return twice;
}
as you can see, we did not write two versions of the same source code(#3)
and both functions give the same result(#1) and satisfies #4 and the rest with the remainding header files.
but somehow,
I have a feeling (as usual...) what 7stud and Lindley said is more likely to be your answer.
see ya!
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
|