Volatile variable

I have a volatile variable in a class. Want to write a function that returns the address of this variable. How do I do that? Simple putting & is not working.. :(
afaik (I haven't tested this)... volatile is a characteristic of the variable just like const is. So you'd need to have the pointer declared as volatile as well:

1
2
3
4
5
6
7
8
9
10
11
12
class A
{
public:
  volatile int* get() { return &p; }
protected:
  volatile int p;
};

///////

A a;
volatile int* ptr = a.get();
But don't you think, their use is different. As volatile int means, its value may change out of the scope and at any time. Where as voltaile pointer means the address may change any time.

Even if it works, why do we need to do that. What is the logic? Can you please explain this?
Topic archived. No new replies allowed.