0

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?

Niall
  • 30,036
  • 10
  • 99
  • 142
user63898
  • 29,839
  • 85
  • 272
  • 514
  • 3
    Why do you need to pass references to pointers? You're not modifying them, so you can drop the `&` from the arguments. – Drew McGowen Sep 23 '14 at 06:05
  • yeah i did try this also still gives me error: rror LNK2019: unresolved external symbol "public: void __thiscall ParticleFactory::StopAndRemoveParticals(class cocos2d::ParticleSystemQuad * &,class SolutionContainer *)" (??$StopAndRemoveParticals@VSolutionContainer@@@ParticleFactory@@QAEXAAPAVParticleSystemQuad@cocos2d@@PAVSolutionContainer@@@Z) referenced in function "public: void __thiscall SolutionContainer::InnerCleanPreviousLevel(void)" (?InnerCleanPreviousLevel@SolutionContainer@@QAEXXZ) – user63898 Sep 23 '14 at 06:10
  • 1
    Did you change both the declaration (in the header) and the definition (in the cpp file)? – Drew McGowen Sep 23 '14 at 06:10
  • @user63898: The link error is probably because you're defining the template in one source file and using it in another. You usually need to define templates in headers: http://stackoverflow.com/questions/495021 – Mike Seymour Sep 23 '14 at 06:22
  • BTW, you should avoid C-Cast. – Jarod42 Sep 23 '14 at 07:47

1 Answers1

0

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.

Tafuri
  • 468
  • 2
  • 7