is it possible that the parameters of the one function is globally used without using any global variable?
1 2 3 4 5 6 7 8 9 10 11
void myclass::myclass() { /** code here */ }
void myclass::thefunction(int x, char y)
{
/** code here using the x & y */
}
void myclass::thefunction2()
{
/** code here also using the x & y */
}
I am not sure that I really understand what you are saying. But if you wish to share variables between member functions then I suppose that is what member variables are for:
class myclass
{
private:
int x;
int y;
public:
myclass(): x(0), y(0) {}
void thefunction()
{
// code using x, y
}
void thefunction2()
{
// code using x, y
}
}
void myclass::myclass() { /** code here */ }
void myclass::thefunction(int x, char y)
{
/** code here using the x & y */
}
void myclass::thefunction2()
{
printf("%d - %", x , y); /** which displays number 2 and letter t */
}
Well you will either have to pass the variables as many times as necessary for the function you want to have access on them, or you can make them global, or you can make them data members of the class which this function belongs to.
class myclass
{
public:
myclass (){}
~myclass(){}
funct1(int a,b){}
funct2(){}
private:
int x;
int y;
}
myclass::funct1(int a,b)
{
a=x;
b=y;
}
myclass:funct2()
{
//code that deals with x and y (which are equal to a,b parameters)
}
The x and y are defined only within the function scope. Once the function is over, they don't exist anymore.
I'm not clear on what you want to do, but if you want to pass x and y once to thefunction so that you won't have to pass it to thefunction2 again, your only way is to define them as members of myclass.
you can add a part to thefunction which saves the x and y value in the relevant members. Or you can initialize them in the construction of myclass, and you won't have to pass the values to thefunction even.