0

I have some function func in a class Class:

 void func(int arg1, int arg2, Vector2f vec = Vector2f(0,0)){}; 

And I get a build error:

error C2572: 'Classs::func': redefinition of default argument: parameter 1

I tried many different synataxes but none worked. How can I define a default parameter of this type?

1 Answers1

4

Specify the default parameter in the prototype only. Don't repeat this in the function definition.

// prototype
void func(int arg1, int arg2, Vector2f vec = Vector2f(0,0));

// definition
void func(int arg1, int arg2, Vector2f vec)
{
    ...
}

This advice applies to any default parameter. It's got nothing to do with the type.

john
  • 85,011
  • 4
  • 57
  • 81