Déclaration de fonction amie
Bonsoir,
je cherche à déclarer une fonction amie mais j'obtiens l'erreur suivante avec g++:
Citation:
In file included from main.cpp:2:0:
vector.hpp: In instantiation of ‘example::Vector<example::sequential>’:
main.cpp:11:40: instantiated from here
vector.hpp:23:27: erreur: template-id ‘dot<>’ for ‘PetscErrorCode example::dot(const example::Vector<example::sequential>&, const example::Vector<example::sequential>&, PetscScalar*)’ does not match any template declaration
J'ai beau relire mon code, je ne vois pas où je commets une erreur.
La fonction amie est déclarée dans une classe Vector
Code:
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
| #ifndef VECTOR_HPP
#define VECTOR_HPP
#include <petscvec.h>
// forward declaration of vector
#include "vector_fwd.hpp"
namespace example {
// forward declaration of dot function
template< template<class> class DistributionPolicy >
PetscErrorCode dot(Vector<DistributionPolicy> const & x , Vector<DistributionPolicy> const & y , PetscScalar * val);
template< template<class> class DistributionPolicy >
class Vector : public DistributionPolicy<Vec>
{
friend PetscErrorCode dot<>(Vector<DistributionPolicy> const & x , Vector<DistributionPolicy> const & y , PetscScalar * val);
private:
Vec m_self;
};
}
#include "vector_friend.hpp" |
et la fonction amie est définie par
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| #ifndef VECTOR_FRIEND_HPP
#define VECTOR_FRIEND_HPP
namespace example {
template< template<class> class DistributionPolicy >
inline PetscErrorCode dot(Vector<DistributionPolicy> const & x,
Vector<DistributionPolicy> const & y,
PetscScalar* val) {
PetscErrorCode code = VecDot(x.m_self,y.m_self,val);
CHKERRQ(code);
return 0;
}
}
#endif |
Est-ce que vous voyez où se situe le problème?