• Advertisement
Sign in to follow this  

Problem with multyple function with same name but different parameters and i get errors

This topic is 1387 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello.

AFAIK this should work:

If you know why i am getting this, please help!

//HPP
void AddSpecialEffect(int posX, int posY, SpecialEffect & specialEffect, int * SpecialEffectVecID);
void AddSpecialEffect(int UnitVecID, SpecialEffect & specialEffect, int * SpecialEffectVecID);
 
//CPP
void SpecialEffectHolder::AddSpecialEffect(int PosX, int PosY, SpecialEffect & specialEffect, int * SpecialEffectVecID = 0)
{
    
}
void SpecialEffectHolder::AddSpecialEffect(int UnitVecID, SpecialEffect & specialEffect, int * SpecialEffectVecID = 0)
{
   
}

The compiler error

1>main.cpp(109): error C2664: 'void SpecialEffectHolder::AddSpecialEffect(int,SpecialEffect &,int *)' : cannot convert parameter 2 from 'int' to 'SpecialEffect &'
1>main.cpp(110): error C2664: 'void SpecialEffectHolder::AddSpecialEffect(int,SpecialEffect &,int *)' : cannot convert parameter 2 from 'int' to 'SpecialEffect &'
1>main.cpp(111): error C2664: 'void SpecialEffectHolder::AddSpecialEffect(int,SpecialEffect &,int *)' : cannot convert parameter 2 from 'int' to 'SpecialEffect &'
1>main.cpp(112): error C2664: 'void SpecialEffectHolder::AddSpecialEffect(int,SpecialEffect &,int *)' : cannot convert parameter 2 from 'int' to 'SpecialEffect &'
1>main.cpp(114): error C2661: 'SpecialEffectHolder::AddSpecialEffect' : no overloaded function takes 2 arguments
Edited by BaneTrapper

Share this post


Link to post
Share on other sites
Advertisement


Write the default value into the declaration, not into the definition:

I'm curious as to why this would be a fix. I thought putting the default in either the declaration or the definition was allowed (but not both) -- although I do put my defaults in the declaration as well, as I find it more user friendly.

 

Stack Overflow seems to also agree with both being valid: http://stackoverflow.com/questions/4989483/where-to-put-default-parameter-value-in-c

Share this post


Link to post
Share on other sites

What's the calling code in main, line 109?

Do note i may switch these up and down was testing, apparently adding adding last parameter "NULL" makes the thing work!

objSpecialEffectHolder.AddSpecialEffect(0, SpecialEffect(en::SEL2, 5, 4, 100, sf::Color(255,255,255,255)), NULL);

This is the main call


objSpecialEffectHolder.AddSpecialEffect(0, SpecialEffect(en::SEL2, 5, 4, 100, sf::Color(255,255,255,255)));
    objSpecialEffectHolder.AddSpecialEffect(10, 10, SpecialEffect(en::SEL1, 1, 3, 500, sf::Color(255,255,255,255)));
    objSpecialEffectHolder.AddSpecialEffect(100, 100, SpecialEffect(en::SEL1, 1, 3, 422, sf::Color(255,255,255,255)));
    objSpecialEffectHolder.AddSpecialEffect(99, 290, SpecialEffect(en::SEL1, 0, 4, 500, sf::Color(255,255,255,255)));
    objSpecialEffectHolder.AddSpecialEffect(21, 57, SpecialEffect(en::SEL1, 0, 4, 266, sf::Color(255,255,255,255)));

 

Write the default value into the declaration, not into the definition:

//HPP
void AddSpecialEffect(int posX, int posY, SpecialEffect & specialEffect, int * SpecialEffectVecID = 0);
void AddSpecialEffect(int UnitVecID, SpecialEffect & specialEffect, int * SpecialEffectVecID = 0);


//CPP
void SpecialEffectHolder::AddSpecialEffect(int PosX, int PosY, SpecialEffect & specialEffect, int * SpecialEffectVecID)
{
    
}
void SpecialEffectHolder::AddSpecialEffect(int UnitVecID, SpecialEffect & specialEffect, int * SpecialEffectVecID)
{
   
}

 

This also fixes it, sad.png so much of my code has potential to break, default parameter in declaration.

thanks on information all!

Edited by BaneTrapper

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement