Prevent delete on pointer in C++
<p>Is there any way to prevent deleting a pointer in C++ by its declaration? </p>

<p>I've tried following code without luck.</p>

<pre><code>const int* const foo()
{
    static int a;
    return &amp;a;
}

int main()
{
    const int* const a = foo();

    *a = 1;   //compiler error, const int*
    a++;      //compiler error, int* const
    delete a; //no compiler error, I want to have compiler error here

    return 0;
}
</code></pre>
