简体   繁体   中英

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 is what my template function looks like:

in header

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

in 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 :

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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