I have this code in C++
class ConstantTest
{
public:
typedef set<string> StrSet;
ConstantTest (const uint16_t & id = 0, const string & str = "Empty",
StrSet & set = StrSet()) :
// Works with: const StrSet & set = StrSet()
m_id (id), m_str (str), m_set (set)
{ }
private:
uint16_t m_id;
string m_str;
StrSet m_set;
};
I want to know why it doesn't work without the const
keyword in the StrSet
parameter. With the keyword works just fine, but without it I get this message:
test_const.cpp:17:41: error: could not convert ‘std::set<std::basic_string<char> >()’ from ‘ConstantTest::StrSet {aka std::set<std::basic_string<char> >}’ to ‘ConstantTest::StrSet& {aka std::set<std::basic_string<char> >&}’
StrSet & set = StrSet()) :
^