Reputation: 59
I've encountered a strange problem in my C++ Code. I've defined a TemplateClass called
StateTemplate<T>
Furthermore I defined
typedef StateTemplate<double> StateDouble.
Then I defined a friend function
template<class S>
friend S partialEntangledScalarProduct(
const typename std::vector<StateTemplate<T> >::const_iterator s1,
const typename std::vector<StateTemplate<T> >::const_iterator s2,
const typename std::vector<StateTemplate<T> >::const_iterator sSub1,
const typename std::vector<StateTemplate<T> >::const_iterator sSub2,
vector<unsigned int> const &pos,
vector<unsigned int> const &posNot);
If I now make
std::vector<StateDouble>::const_iterator s1;
std::vector<StateDouble>::const_iterator s2;
std::vector<StateDouble>::const_iterator sSub1;
std::vector<StateDouble>::const_iterator sSub2;
vector<unsigned int> vui;
Doub test=partialEntangledScalarProduct(s1,s2,sSub1,sSub2,vui,vui);
I get the following Error:
no matching function for call to
'partialEntangledScalarProduct(
__gnu_cxx::__normal_iterator<
const StateTemplate<double>*,
std::vector<
StateTemplate<double>,
std::allocator<StateTemplate<double> > > >&,
__gnu_cxx::__normal_iterator<
const StateTemplate<double>*,
std::vector<
StateTemplate<double>,
std::allocator<StateTemplate<double> > > >&,
__gnu_cxx::__normal_iterator<
const StateTemplate<double>*,
std::vector<
StateTemplate<double>,
std::allocator<StateTemplate<double> > > >&,
__gnu_cxx::__normal_iterator<
const StateTemplate<double>*,
std::vector<
StateTemplate<double>,
std::allocator<StateTemplate<double> > > >&,
const std::vector<unsigned int, std::allocator<unsigned int> >&,
std::vector<unsigned int, std::allocator<unsigned int> >&)'
I've tried for hours to find the problem, but it seems that I overlook something. Maybe someone could help me?
best regards Dominik
p.s.: if you need more information about my code, just let me know. At the moment I just wanted to give you the important parts.
Here is a small example with the same error.
#include <iostream>
#include <vector>
template<class T>
class StateTemplate{
template<class S>
friend S testFunction(
const typename std::vector<StateTemplate<S> >::const_iterator s1);
public:
StateTemplate();
};
template<class T>
StateTemplate<T>::StateTemplate(){}
template<class T>
T testFunction(
const typename std::vector<StateTemplate<T> >::const_iterator s1)
{
return T(1);
}
int main(){
std::vector<double>::const_iterator s1;
double s=testFunction<double>(s1);
return 0;
}
Upvotes: 1
Views: 1826
Reputation: 8604
If you presented the declaration of partialEntangledScalarProduct
correctly, the template parameter S
isn't used anywhere in the function parameter list. Therefore, the compiler would never deduce it and you have to provide it explicitly.
partialEntangledScalarProduct<SomeClass>(s1,s2,sSub1,sSub2,vui,vui);
SomeClass
is just an example, the exact name is unclear unless you provide more details.
Upvotes: 2
Reputation: 11677
(I don't have g++ on this machine, so this is conjecture.)
I think the issue is that the compiler can't deduce S
and you're getting an unhelpful error message. Change your usage to the following:
double test = partialEntangledScalarProduct<double>(s1,s2,sSub1,sSub2,vui,vui);
As a side note, make sure your examples compile for you before you post them. I'm assuming Doub
was supposed to be double
?
Upvotes: 1