Hello, I've been having some troubles with classes lately. My issue is this: I want to make a class with a constructor, then make another class with a member which is an object of the first class, and I want to fill in the arguments for the constructor function when I declare this member. Here's an example of the code:
enum func_ability{ high, medium, low};
class motion_control{
public:
bool controller;
func_ability function;
float cost;
motion_control(bool ctrl, func_ability func, float price){
controller = ctrl;
function = func;
cost = price;
}
};
class Xbox_Game{
private:
bool online;
motion_control kinect(false, high, 150.00); //HERE is where my problem is. I know I'm declaring the object properly, yet it still won't work.
};
When I try to build this code, I get the errors:
error: expected identifier before 'false'
error: expected ',' or '...' before 'false'
Is this something you just can't do in C++? Clearly those error messages don't make any sense. The compiler doesn't seem to know what the heck I'm trying to do.
I'll try that, but it doesn't sound right. kinect is going to be a member, so how could I mention it in the constructor without declaring it first? If I declare it without any arguments, it might initialize using the compiler's default constructor, but then I couldn't give it its unique values with my own constructor. Maybe if I made a friend function that acted as a constructor, but then that's beyond the point, really. I'm mostly interested to know if it's possible to initialize an object as a member of a class, calling that object's constructor in the process.