Reputation: 657
I am new to C++ (from C# background) and I have a function with the following signature
void AddBenchNode(ref_ptr<Group> root ,ref_ptr<Node> benches, bool setAttitude = false, float scale_x =.15, float scale_y =15, float scale_z = 15, int positionx = 250, int positiony = 100, int positionz =0 )
{
}
But when I try to call the code as below, I get an error which says function does not take 4 arguments.
//then I try to call my function like so
AddBenchNode(root, benches, false, 250);
but I instead get the following error message
error C2660: 'AddBenchNode' : function does not take 3 arguments
Would appreciate an explanation of how C++ does this instead?
Upvotes: 1
Views: 918
Reputation: 5491
Check the prototype in your .hpp file. It's probably declared as
void AddBenchNode(ref_ptr<Group> root ,ref_ptr<Node> benches, bool setAttitude,
float scale_x, float scale_y, float scale_z, int positionx,
int positiony, int positionz);
EDIT: The prototype in the header should be
void AddBenchNode(ref_ptr<Group> root ,ref_ptr<Node> benches, bool setAttitude = false, float scale_x =.15, float scale_y =15, float scale_z = 15, int positionx = 250, int positiony = 100, int positionz =0 );
And your cpp file should then only have
void AddBenchNode(ref_ptr<Group> root ,ref_ptr<Node> benches, bool setAttitude, float scale_x, float scale_y, float scale_z, int positionx, int positiony, int positionz)
{
}
That is, the default parameters are in the prototype, not in the actual definition.
Upvotes: 7