I am wondering why I get an error when compiling:
const std::unique_ptr<int> get() {
return std::make_unique<int>(10);
}
int main() {
const std::unique_ptr<int> value = get();
return EXIT_SUCCESS;
}
I get the following error:
main.cpp: In function ‘int main()’:
main.cpp:10:44: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = int; _Dp = std::default_delete<int>]’
const std::unique_ptr<int> value = get();
It compiles correctly when I remove const
from the get
signature.
Is there any way to return a constant unique_ptr ?
Thanks!
Aucun commentaire:
Enregistrer un commentaire