Salut,

Je voudrais convertir un int en un constexpr int car j'ai une fonction virtuelle et elle ne peut pas retourner une constexpr.

J'ai cherché par tout les moyens ce qui me résulte à chaque fois en une erreur de compilation :

Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
template <typename I>
    constexpr int intToConstExpr(I expr, const int value) const {
        if (expr != value)
            return intToConstExpr(expr+1, value);
        return expr;
    }

Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
constexpr int cmpt = intToConstExpr(0, getType());

La fonction getType() retourne juste un entier qui me sert d'identifiant pour un type d'objet dérivé.

Voici l'erreur de compilation :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 
||=== Build: Debug in ODFAEG (compiler: GNU GCC Compiler) ===|
/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Physics/../../../include/odfaeg/Physics/boundingVolume.h|38|error: ‘constexpr int odfaeg::BoundingVolume<D>::intToConstExpr(I, int) const [with I = int; D = odfaeg::BoundingBox]’ called in a constant expression|
/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Physics/../../../include/odfaeg/Physics/boundingVolume.h|100|note: ‘constexpr int odfaeg::BoundingVolume<D>::intToConstExpr(I, int) const [with I = int; D = odfaeg::BoundingBox]’ is not usable as a constexpr function because:|
/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Physics/../../../include/odfaeg/Physics/boundingVolume.h|100|error: enclosing class of constexpr non-static member function ‘constexpr int odfaeg::BoundingVolume<D>::intToConstExpr(I, int) const [with I = int; D = odfaeg::BoundingBox]’ is not a literal type|
/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Physics/../../../include/odfaeg/Physics/boundingVolume.h|35|note: ‘odfaeg::BoundingVolume<odfaeg::BoundingBox>’ is not literal because:|
/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Physics/../../../include/odfaeg/Physics/boundingVolume.h|35|note:   ‘odfaeg::BoundingVolume<odfaeg::BoundingBox>’ has a non-trivial destructor|
/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Physics/../../../include/odfaeg/Physics/boundingVolume.h|39|error: no matching function for call to ‘get(std::tuple<odfaeg::BoundingBox*>&)’|
/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Physics/../../../include/odfaeg/Physics/boundingVolume.h|39|note: candidates are:|
/usr/include/c++/4.8/utility|142|note: template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(std::pair<_Tp1, _Tp2>&)|
/usr/include/c++/4.8/utility|142|note:   template argument deduction/substitution failed:|
/usr/include/c++/4.8/utility|147|note: template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&& std::get(std::pair<_Tp1, _Tp2>&&)|
/usr/include/c++/4.8/utility|147|note:   template argument deduction/substitution failed:|
/usr/include/c++/4.8/utility|152|note: template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr const typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(const std::pair<_Tp1, _Tp2>&)|
/usr/include/c++/4.8/utility|152|note:   template argument deduction/substitution failed:|
/usr/include/c++/4.8/array|268|note: template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp& std::get(std::array<_Tp, _Nm>&)|
/usr/include/c++/4.8/array|268|note:   template argument deduction/substitution failed:|
/usr/include/c++/4.8/array|277|note: template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp&& std::get(std::array<_Tp, _Nm>&&)|
/usr/include/c++/4.8/array|277|note:   template argument deduction/substitution failed:|
/usr/include/c++/4.8/array|285|note: template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr const _Tp& std::get(const std::array<_Tp, _Nm>&)|
/usr/include/c++/4.8/array|285|note:   template argument deduction/substitution failed:|
/usr/include/c++/4.8/tuple|757|note: template<long unsigned int __i, class ... _Elements> constexpr typename std::__add_ref<typename std::tuple_element<__i, std::tuple<_Elements ...> >::type>::type std::get(std::tuple<_Elements ...>&)|
/usr/include/c++/4.8/tuple|757|note:   template argument deduction/substitution failed:|
/usr/include/c++/4.8/tuple|764|note: template<long unsigned int __i, class ... _Elements> constexpr typename std::__add_c_ref<typename std::tuple_element<__i, std::tuple<_Elements ...> >::type>::type std::get(const std::tuple<_Elements ...>&)|
/usr/include/c++/4.8/tuple|764|note:   template argument deduction/substitution failed:|
/usr/include/c++/4.8/tuple|771|note: template<long unsigned int __i, class ... _Elements> constexpr typename std::__add_r_ref<typename std::tuple_element<__i, std::tuple<_Elements ...> >::type>::type std::get(std::tuple<_Elements ...>&&)|
/usr/include/c++/4.8/tuple|771|note:   template argument deduction/substitution failed:|
/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Physics/../../../include/odfaeg/Physics/boundingVolume.h|40|error: no matching function for call to ‘get(std::tuple<odfaeg::BoundingBox*>&)’|
/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Physics/../../../include/odfaeg/Physics/boundingVolume.h|40|note: candidates are:|
/usr/include/c++/4.8/utility|142|note: template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(std::pair<_Tp1, _Tp2>&)|
/usr/include/c++/4.8/utility|142|note:   template argument deduction/substitution failed:|
/usr/include/c++/4.8/utility|147|note: template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&& std::get(std::pair<_Tp1, _Tp2>&&)|
/usr/include/c++/4.8/utility|147|note:   template argument deduction/substitution failed:|
/usr/include/c++/4.8/utility|152|note: template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr const typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(const std::pair<_Tp1, _Tp2>&)|
/usr/include/c++/4.8/utility|152|note:   template argument deduction/substitution failed:|
/usr/include/c++/4.8/array|268|note: template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp& std::get(std::array<_Tp, _Nm>&)|
/usr/include/c++/4.8/array|268|note:   template argument deduction/substitution failed:|
/usr/include/c++/4.8/array|277|note: template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp&& std::get(std::array<_Tp, _Nm>&&)|
/usr/include/c++/4.8/array|277|note:   template argument deduction/substitution failed:|
/usr/include/c++/4.8/array|285|note: template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr const _Tp& std::get(const std::array<_Tp, _Nm>&)|
/usr/include/c++/4.8/array|285|note:   template argument deduction/substitution failed:|
/usr/include/c++/4.8/tuple|757|note: template<long unsigned int __i, class ... _Elements> constexpr typename std::__add_ref<typename std::tuple_element<__i, std::tuple<_Elements ...> >::type>::type std::get(std::tuple<_Elements ...>&)|
/usr/include/c++/4.8/tuple|757|note:   template argument deduction/substitution failed:|
/usr/include/c++/4.8/tuple|764|note: template<long unsigned int __i, class ... _Elements> constexpr typename std::__add_c_ref<typename std::tuple_element<__i, std::tuple<_Elements ...> >::type>::type std::get(const std::tuple<_Elements ...>&)|
/usr/include/c++/4.8/tuple|764|note:   template argument deduction/substitution failed:|
/usr/include/c++/4.8/tuple|771|note: template<long unsigned int __i, class ... _Elements> constexpr typename std::__add_r_ref<typename std::tuple_element<__i, std::tuple<_Elements ...> >::type>::type std::get(std::tuple<_Elements ...>&&)|
/usr/include/c++/4.8/tuple|771|note:   template argument deduction/substitution failed:|
/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Physics/../../../include/odfaeg/Physics/boundingVolume.h||In instantiation of ‘odfaeg::BoundingVolume<D>* odfaeg::BoundingVolume<D>::clone() [with D = odfaeg::BoundingBox]’:|
/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Physics/boundingBox.cpp|261|required from here|
/home/laurent/Développement/Projets-c++/ODFAEG/src/odfaeg/Physics/../../../include/odfaeg/Physics/boundingVolume.h|78|warning: no return statement in function returning non-void [-Wreturn-type]|
Voila donc je voudrais savoir si il y a moyen de convertir un int en une constexpr.