I asked this question: Array Equivalent of Bare-String
To which the answer was C++ doesn't provide this functionality for const int*
s. Which is disappointing. So my question then is: In practice how do I get around this limitation?
I want to write a struct like this:
struct foo{
const char* letters = "abc";
const int* numbers = ???
};
I cannot:
&{1, 2, 3}
cause I can't take the address of an r-valuearray<int, 3>{{1, 2, 3}}.data()
cause the memory is cleaned up immediately after initializationconst int* bar(){ return new int[3]{1, 2, 3}; }
cause nothing will delete this pointer
I know that I can use an auto pointer to get around this. I am not suggesting that struct foo
is good code, I am trying to illustrate that the compiler makes a provision to store the const array "abc"
in memory and clean it up on program exit, I want there to be a way to do that for int
s as well.
Is there a way to accomplish this?