Question: I am getting following error `error: invalid conversion from ‘const int*’ to ‘int*’`
Following is my program

```
#include <set>
int main ( int argc, char **argv) {
    std::set<int> intSet;
    intSet.insert(1);
    intSet.insert(2);
    intSet.insert(3);
    intSet.insert(4);
    intSet.insert(5);

    int *pAddress = &(*(intSet.find(4)));
}

```

I want address of the element in the `std::set` , This code does not give any compilation error with Microsoft compiler but `g++` is giving this compilation error.

Answer: 
It is because each element of `std::set` is stored as `T const`, and the implementation has a reason to do so.

Since `std::set` contains exactly a single copy of a value. It has to make it *immutable*, otherwise, one can change it's value to something which already exists in the set.

Even if the elements were *mutable*, you would not be able the change the value, because `std::set::find` is a `const` member function, and therefore in this function `intSet` is *immutable* and effectively each elements would become *immutable* as well, including the *iterator* which it returns, and through which you *may* change the value at the call-site.

The only want to take the address is this:

```
int const *paddress =  &(*(intSet.find(4))); //const int* is same as int const*

```

Don't use `const_cast` though,

```
//DANGEROUS - DONT DO IT
int *paddress =  const_cast<int*>(&(*(intSet.find(4)))); //will compile, 
                                                       //but it is dangerous!

//you might accidentally write
*paddress = 10; //undefined behaviour, 
                //though the compiler will let you write this

```
GCC [defines](http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14410) `set::iterator` to be `set::const_iterator`, preventing you from binding a non-`const` reference or pointer to the result of `set::find()`. This behaviour is allowed by C++11 (which states that keys are immutable, and that `set::iterator` is a constant iterator), but was incorrect in C++03.

In C++03, you shouldn't modify the elements of a set since that can break the ordering of elements within it. In some cases, you might want to - if the type is a class, and only some members are used to define the ordering, then it was valid to modify other members. The C++03 standard allows this, but you must be careful not to modify the order as that will give undefined behaviour. In C++11, this isn't allowed, and the implementation may prevent this.

In your case, you can't legally modify the value at all, so you can fix your code for C++11, and also improve its safety, by binding to a pointer-to-const.

```
int const *pAddress = &(*(intSet.find(4)));

```