简体   繁体   English

将“ this”传递到功能模板中,出现错误

[英]Pass 'this' into function template, gives error

I try to pass to function template from other object the object this but it keep to give me compilation error. 我尝试this对象的其他对象传递给功能模板,但它一直给我编译错误。 This is what my template function looks like: 这是我的模板函数的样子:

in header 在标题中

template<class T>
    void StopAndRemoveParticals(ParticleSystemQuad* &emitter,T* &parent);

in c++ 在C ++中

template<class T> 
    void ParticleFactory::StopAndRemoveParticals(ParticleSystemQuad* &emitter,T* &parent)
    {
        bool ParticlesEmitterIsActive = emitter->isActive();
        if(emitter!= NULL)
        {        
            particaleTagName tag = (particaleTagName)emitter->getTag();
            parent->m_Parent->removeChildByTag(emitter->getTag());
        }
    }

calling this function from Some object : 从Some对象调用此函数:

1>\projects\game\classes\solutioncontainer.cpp(114): error C2664: 'void ParticleFactory::StopAndRemoveParticals<SolutionContainer>(cocos2d::ParticleSystemQuad *&,T *&)' : cannot convert parameter 2 from 'SolutionContainer *const ' to 'SolutionContainer *&'
1>          with
1>          [
1>              T=SolutionContainer
1>          ]

What am I doing wrong here and why can't I pass pointer to reference? 我在这里做错了什么,为什么我不能传递指向引用的指针?

This seems to be both an issue with const (you are probably trying to call StopAndRemoveParticals from another const member function), and an issue with trying to get a reference to the this pointer. 这似乎既是const的问题(您可能正在尝试从另一个const成员函数调用StopAndRemoveParticals ),又是试图获取对this指针的引用的问题。

The code does not seem to require references to pointers, so start by removing them. 该代码似乎不需要引用指针,因此请先删除它们。 Solving the const problem will require you to make modifications in the function calling StopAndRemoveParticals . 解决const问题将需要您在调用StopAndRemoveParticals的函数中进行修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM