P
Pierre Yves
Hello,
I've got a little piece of code that is giving me grief. The example
I've included demonstrates the problem (the code will make no sense i.e
why have friend functions when I'm not accessing private members etc but
the real code does actually have proper implementation). This code
should go in a header file then just build.
//==============================================================
#ifndef _TEST_H_
#define _TEST_H_
#include <math.h>
namespace sb
{
template<class T>
class CVector;
template<class S>
CVector<S> pow(const CVector<S> & A, int n);
template<class S>
void SVD(const CVector<S> A);
template <class T>
class CVector
{
public:
CVector();
virtual ~CVector ();
template<class S>
friend CVector<S> pow(const CVector<S> & A, int n);
template <class S>
friend void SVD(const CVector<S> A);
};
template<class T>
CVector<T> pow(const CVector<T> & A, int n)
{
CVector<T> S=A;
for (unsigned int i=1; i<n; i++)
{
S = S*A;
}
return S;
}
template <class T>
void SVD(const CVector<T> A)
{
double result = pow(2.0,6.0);
}
}
#endif
//==============================================================
The error is:
In file included from main.cpp:2:
test.h: In function ‘void sb::SVD(sb::CVector<S>)’:
test.h:44: error: no matching function for call to ‘pow(double, double)’
It seems as if I can't use pow in math.h even though its included. Its
like my definition of pow is the only one. My compiler is gcc 4.2.5.
Anyone got any hints to what is wrong?
Cheers,
Pierre.
I've got a little piece of code that is giving me grief. The example
I've included demonstrates the problem (the code will make no sense i.e
why have friend functions when I'm not accessing private members etc but
the real code does actually have proper implementation). This code
should go in a header file then just build.
//==============================================================
#ifndef _TEST_H_
#define _TEST_H_
#include <math.h>
namespace sb
{
template<class T>
class CVector;
template<class S>
CVector<S> pow(const CVector<S> & A, int n);
template<class S>
void SVD(const CVector<S> A);
template <class T>
class CVector
{
public:
CVector();
virtual ~CVector ();
template<class S>
friend CVector<S> pow(const CVector<S> & A, int n);
template <class S>
friend void SVD(const CVector<S> A);
};
template<class T>
CVector<T> pow(const CVector<T> & A, int n)
{
CVector<T> S=A;
for (unsigned int i=1; i<n; i++)
{
S = S*A;
}
return S;
}
template <class T>
void SVD(const CVector<T> A)
{
double result = pow(2.0,6.0);
}
}
#endif
//==============================================================
The error is:
In file included from main.cpp:2:
test.h: In function ‘void sb::SVD(sb::CVector<S>)’:
test.h:44: error: no matching function for call to ‘pow(double, double)’
It seems as if I can't use pow in math.h even though its included. Its
like my definition of pow is the only one. My compiler is gcc 4.2.5.
Anyone got any hints to what is wrong?
Cheers,
Pierre.