错误:模板化复制构造函数调用自身 [英] Error: templated copy constructor calls itself

查看:176
本文介绍了错误:模板化复制构造函数调用自身的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的应用程序中调用此复制构造函数时,此复制构造函数进入无限循环,即它保持调用自身。
当我调试的pogram终止在第一行本身。
使用的foreach循环是一个Qt foreach。

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);
    }
}


推荐答案

Qt文档


当Qt进入foreach循环时,Qt自动获取一个副本。

Qt automatically takes a copy of the container when it enters a foreach loop.

这篇关于错误:模板化复制构造函数调用自身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆