I created a structure, and its members are objects that require a constructor with an argument to be called to work. How do I call the objects' constructors when I declare an instance of the structure?
This is the structure:
Code:
struct full_set
{
key n,e,d;//n, e, and d are instances of the key class.
};
This is the key class:
Code:
class key
{
public:
key(int);//key.length is set to the value passed to the constructor.
//Other member functions
private:
int *keyset;//keyset is a dynamic array
bool *defined_keys;//defined_keys is a dynamic array
int length;//length is the length of the dynamic arrays
};
key::key(int set_length)
{//key.length is set to the value passed to the constructor.
length = set_length;
//Also, create the dynamic arrays.
keyset = new int[length];
defined_keys = new bool[length];
//more code
}
Since the constructor in the key class creates the dynamic arrays, it needs to be called whenever an instance is created. When I create an instance of the full_set structure, how do I call the constructor for its members?