C
claire.bell1
Hi,
Im having problems initialising class member objects in the class's
constructor
e.g. My program isnt about monkeys, but there is too much code to post here.
class monkey
{
private:
int age;
public:
monkey(int);
};
monkey::monkey(int a)
{
age = a;
}
ok class monkey is pretty irrelevant, it will be a member object for person
class person{
private:
monkey ownedMonkey;
public:
person(int)
};
person:erson(int monkeyAge)
{
ownedMonkey(monkeyAge);
}
basically im not sure how to initialise the owned monkey in the person's
constructor. When I try to compile my code it says there is no constructor
for monkey(void), even though im using a value.
Anyone know how to correctly initialise member objects?
Thanks,
Vipa
Im having problems initialising class member objects in the class's
constructor
e.g. My program isnt about monkeys, but there is too much code to post here.
class monkey
{
private:
int age;
public:
monkey(int);
};
monkey::monkey(int a)
{
age = a;
}
ok class monkey is pretty irrelevant, it will be a member object for person
class person{
private:
monkey ownedMonkey;
public:
person(int)
};
person:erson(int monkeyAge)
{
ownedMonkey(monkeyAge);
}
basically im not sure how to initialise the owned monkey in the person's
constructor. When I try to compile my code it says there is no constructor
for monkey(void), even though im using a value.
Anyone know how to correctly initialise member objects?
Thanks,
Vipa