Why are my default/optional parameters being ignored?
grid_model.h
class GridModel {
public:
GridModel();
void PrintGrid(bool);
};
grid_model.cpp
void GridModel::PrintGrid(bool flag = false) {
// things...
}
grid_model_test.cpp
ns::GridModel* gm = new GridModel();
gm->PrintGrid(true); // works
gm->PrintGrid(); // doesn't work
error:
grid_model_test.cpp:22:12: error: no matching function for call to ‘ns::GridModel::PrintGrid()’
gm->PrintGrid();
^
In file included from grid_model_test.cpp:2:0:
grid_model.h:27:7: note: candidate: void ns::GridModel::PrintGrid(bool)
void PrintGrid(bool);
^~~~~~~~~
When I use them elsewhere, they seem to work fine.
#include <iostream>
class Thing {
public:
void Whatever(bool);
};
void Thing::Whatever(bool flag = false) {
std::cout << "Parameter was: " << flag << std::endl;
}
int main() {
Thing* thing = new Thing();
thing->Whatever();
return 0;
}