I inclue the file but the function could not be seen

Mar 11, 2016 at 3:57pm
Hi every one
I really appreciate If you can help me in this problem.
I have a page called s.cpp with a function in it called "calculate" like below
 
 float Sim::calculate(float e){}


As I want to use it in another page called p.cpp I include s.h on the c.pp
but when I wrote down the name of function it is not recognized

1
2
3
4
5
6
7
8
                        if(x!=-1)
			{
				.....//some codes
			}
			else
			{
                               float newE = calculate(e); 
			}


Can you guess why it is not recognized?
Thank you in advance for any comments
Mar 11, 2016 at 3:59pm
Probably because you didn't add s.cpp to your project or compile line so the linker couldn't find the implementation.
Mar 11, 2016 at 4:04pm
Are you talking about a compile-time error, or a link-time error?

If you have error messages, then tell us what those errors are. I cannot understand why you thought it would be better to withhold that information from us!
Mar 11, 2016 at 4:15pm
Thank you for your response. It is a link-time error and it is said : "Function 'calculate' could not be resolved". I use Eclipse for write down codes
Mar 11, 2016 at 4:17pm
Thanks jlb for your comment.
What is compile line?
all of my files is in one project.
Mar 11, 2016 at 4:26pm
One obvious thing is that you've defined your function as:

float Sim::calculate(float e){}

What is Sim? A namespace? A class?

The snipped of calling code you've shown us doesn't give us any clue about how it knows that it's looking for the function in something called Sim.
Last edited on Mar 11, 2016 at 4:46pm
Mar 11, 2016 at 4:36pm
Sim is the class that is defined in the h file of the s page
Mar 11, 2016 at 4:46pm
And that bit of code you've shown us that tries to call calculate() - is that part of the class too?

Because if it isn't, then the code is trying to call a free function called calculate(), which is not the same thing as Sim::calculate().
Mar 11, 2016 at 4:59pm
class Sim {
public:
float calculate(float e)
}
yes it is defined in this s.h page
Mar 11, 2016 at 5:04pm
I'm asking about the code that calls calculate(). It needs to call that method on an object of type Sim. Where is that object?
Topic archived. No new replies allowed.