Some code: Please see the class myClass below . it has a constructor and a public recursive function find. Please see code:
#include <iostream> using namespace std; class myClass{ public: myClass() { //do stuff } int find(int i) { static int j = 10; if (i > 15) return i; j = j + 1; return i * find(j + 1); } }; int main() { myClass mC1 ,mC2; cout<< " 1.... return value = "<< mC1.find(10); cout<< " \n 2... return value = "<< mC2.find(10); return 1; } output:
1.... return value = 5241600 2.... return value = 170 The above progemn has a class myclass having a function find .. "find" function has a variabe . This is static which is required as i wanted a recursive function . Problem is static varible has life of a program & binded to class .
However I want the static to be object specfic and not class scope . I wanted both the function calls to return me same value .
Simply put , how to make a static varable in a class function , to be per object and not for whole class...