Line 16: This is a default constructor with no arguments.
Line 22: This constructor has three arguments. All have defaults values, which means it is legal to call this constructor with no arguments.
Line 6: You instantiate mnemonic_one with no arguments. Which constructor is the compiler supposed to call? The default constructor, or the one with all three arguments defaulted?
Two possible solutions:
1) Change line 22 so that ID is not defaulted. That will make the constructors different enough so the compiler will know which one you want.
2) Get rid of the default constructor.
some identifiers are reserved for use by C ++ implementations and shall not be used otherwise; no diagnostic is required.
Each identifier that contains a double underscore __ or begins with an underscore followed by an uppercase letter is reserved to the implementation for any use.
Each identifier that begins with an underscore is reserved to the implementation for use as a name in the global namespace.
Member functions defined in the header, outside the class definition should be declared inline Otherwise, there would be an ODR violation if the header is included in more than one translation unit.
One Definition Rule: http://en.cppreference.com/w/cpp/language/definition
The rules for function overload resolution apply for selecting the constructor of a class.
If a class has more than one default constructor, default initialisation of an object would be ambiguous.
For instance:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
struct A
{
static A sa ;
A() ; // (1) default constructor
A( int = 8, bool = true ) ; // (2) default constructor
A( const A& = sa, int = 99 ) ; // (3) default constructor, copy constructor
};
int main() //
{
A a1(45) ; // fine: constructor (2)
A a2(a1) ; // fine: copy constructor: constructor (3)
A a3( 45, false ) ; // fine: constructor (2)
A a4( a3, 78 ) ; // fine: constructor (3)
A a5 ; // *** error *** ambiguous: constructors (1), (2) and (3) are all viable candidates
}
The problem is that you have specified a default argument for all parameters in the other constructor. If some of the arguments are left out the default arguments will be passed instead. When you do not specify any of the arguments the compiler don't know which constructor to use.
1 2 3 4 5 6 7 8 9 10 11 12
// Calls mnemonic_one(2, false, '?')
mnemonic_one(2, false, '?');
// Calls mnemonic_one(2, false, '+')
mnemonic_one(2, false);
// Calls mnemonic_one(2, true, '+')
mnemonic_one(2);
// What should this call? mnemonic_one(0, true, '+') or mnemonic_one()?
// The compiler doesn't know so it gives an error.
mnemonic_one();
In the tutorial example there is only one constructor that match when no arguments are passed so there is no ambiguity. In your example there are two constructors that match.
If it called the constructor with no parameters in this situation it would mean that the default argument for ID is useless, and would never be used.
The solution to your problem is very simple. Just leave out the default argument for ID.
A default argument only makes sense if you want the constructor to be called when the argument is left out. You are obviously saying you don't want this constructor to be called when ID is left out so then ID should not have a default argument.