How do I write a constructor that can take in a default parameter? Do I declare the default parameter when declaring private data members or inside the constructor itself?
Color class:
private:
int red;
int blue;
int green;
public:
Color(int r, int b, int g) {red = r; blue = b; green = g;}
Table class:
private:
double weight;
double height;
double width;
double length;
Color green;
public:
Table(double input_weight, double input_height, double input_width,
double input_length, Color green = green(0, 0, 60)){
weight = input_weight;
height = input_height;
width = input_width;
length = input_length;
}
I would like to be able to write a constructor that takes a default parameter. But I don't know how to write one (The above Table constructor is the one I'm having problems with). I would like to have an object Table that has different weights, heights, widths, lengths, but all tables will be green. Thanks for the help!
Aucun commentaire:
Enregistrer un commentaire