I want to design a function so that the parameter is optional and default constructed if left out. The parameter is a struct that I've defined in the same header file. The tried to use the following function declaration:
void publish(MarkerStyle style=MarkerStyle());
When I try to compile I get the following error message:
error: no matching function for call to ‘bob::MarkerStyle::MarkerStyle(bob::MarkerStyle)’
void publish(MarkerStyle style=MarkerStyle());
Is there some way to invoke the default constructor of MarkerStyle as an optional parameter?
EDIT:
Here is my header file.
struct MarkerStyle()
{
double alpha;
std::auto_ptr<Color> color;
MarkerStyle() :
alpha(100)
{}
};
class Publisher
{
void publish(MakerStyle style=MarkerStyle());
};
I understand Bo Perreson's answer. Now my question is why doesn't my code generate a copy constructor for MarkerStyle?
EDIT:
I figured out the problem. auto_ptr prevented copy constructor generation.