wow i didn't thout i get so many replies so fast...
so if i undrstand cprrectly when i do :
Code:
class foo{
type varibale;
..
..
public:
type& func();
}
type & func(){
return varibale;
}
what i do is acualy return a refernce (private case of a normal pointer)to the local varibale
so it is actually like :
Code:
#include <iostream>
using namespace std;
class foo
{
int x;
public:
foo();
int* value();
void print();
};
foo::foo()
{
x=1;
}
int* foo::value()
{
return &x;
}
void foo::print()
{
cout<<x<<endl;
}
int main()
{
foo *a=new foo;
int *ptr = a->value();
a->print();
*ptr=2;
a->print();
return 0;
}
p.s.
if we used the same attitude in c++ like in our life we would call a refernce a fantic pointer (will never change his opnion)
XD