I have a function like (please don't care about returning temporary by reference. This is just an example to explain the problem),
const foo<const int>& get_const()
{
foo<int> f;
return f;
}
This obviously won't compile. I am looking for a way to ensure callers won't change the T
of foo
. How can I ensure that?
I have seen the similar behavior for boost::shared_ptr
. shared_ptr<T>
is convertible to const shared_ptr<const T>
. I couldn't figure out how it is doing this.
Any help would be great.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…