tags:

views:

94

answers:

4

Hi,

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;
}
+1  A: 

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

X::pqr(10, 20)
Ignacio Vazquez-Abrams
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)
David Rodríguez - dribeas
A: 

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;
}
Paul R
The class qualification is not needed as `X::xyz` is already within the class context.
David Rodríguez - dribeas
@David: True - the class qualification is redundant but harmless - I guess it depends on your preferred coding style.
Paul R
+1  A: 

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.

Igor Krivokon
ya i have edited then...
iSight
A: 

Change the following line:

static X::void xyz()

to this:

void X::xyz()
Donotalo