Reputation: 25265
Consider the class Mixer:
class Mixer{
int numChannels;
public: Mixer(int numChannels = 2):numChannels(numChannels){
}
}
I have a subclass called Adder. I'd like the default of numChannels in adder to be 1. How can I achieve this?
Upvotes: 0
Views: 1078
Reputation: 60768
Don't use default arguments - provide a default constructor that takes no inputs and sets it to the default you want.
Upvotes: 0
Reputation: 7324
Change the default value in the constructor of Adder:
class Adder: public Mixer {
public:
Adder(int numChannels = 1): Mixer(numChannels) {}
};
Upvotes: 4
Reputation: 81349
Something like this:
class Adder : Mixer
{
public:
Adder(int numChannels = 1) : Mixer(numChannels){}
};
Upvotes: 5