I want to gave a default value (of empty) for a vector of int pairs in a constructor (C++ 98). I've tried things along the following and it (obviously) doesn't work. Could anyone point me in the right direction?
SomeClassName(
const int replace = 1,
const std::vector<std::pair<int, int> > node = std::vector<std::pair<int, int>() >()
);
If you are trying to write a constructor that accepts a
vector
as input, and you want to make that argument optional, then either:define two constructors, one that takes a
vector
and one that doesn't:define a single constructor that takes the
vector
argument with a default-constructedvector
as a default value (this is what you are already trying to do, but your syntax is wrong):