0

how can i call a function which computes with input parameters from an another static function.

say,

class X
{
   static void xyz();

   static int pqr(int, int);
};

void X::xyz()
{
...pqr(10,20);

}

int X::pqr(int t1, int t2)
{

  return t1*t2;
}
2
  • I think you need to be a bit more detailed in your question here - what is it exactly that you want to do ? Commented May 10, 2010 at 9:59
  • 2
    Shouldn't it be void X::xyz() instead of X::void xyz() ? Commented May 10, 2010 at 10:02

4 Answers 4

1

1) Call it just like pqr(10, 20);

2) You have an error in xyz() definition. It should be

void X::xyz()

Note: you don't need static keywords in the definition of the function, only in the declaration.

Sign up to request clarification or add additional context in comments.

Comments

0

You have to call instance methods off an instance of the class. Otherwise, just call it off the class.

X::pqr(10, 20)

1 Comment

The qualification is not even needed if you are calling from within the class context (which includes the definition of other static class member functions)
0

Change the following line:

static X::void xyz()

to this:

void X::xyz()

Comments

0

Your question is very vague, but it looks like you just need to do something like this:

void X::xyz()
{
    int foo = X::pqr(10, 20);
}

int X::pqr(int t1, int t2)
{
    return t1*t2;
}

2 Comments

The class qualification is not needed as X::xyz is already within the class context.
@David: True - the class qualification is redundant but harmless - I guess it depends on your preferred coding style.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.