Error: templated copy constructor calls itself

两盒软妹~` 提交于 2019-12-08 04:13:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!