问题
when this copy constructor is called in my application, this copy constructor goes into an infinite loop i.e it keeps calling itself. When i debugged the pogram terminated at the first line itself. The foreach loop used is a Qt foreach.
template<class TValue>
Locus<TValue>::Locus (const Locus<TValue>& source ) : QVector<TValue>(source) // program terminates here
{
std::cout << "calling self from here " << std::endl;
foreach (typename Locus<TValue>::value_type l, source)
{
this->push_back(l);
}
}
回答1:
From the Qt docs:
Qt automatically takes a copy of the container when it enters a foreach loop.
来源:https://stackoverflow.com/questions/9887508/error-templated-copy-constructor-calls-itself