Hi guys,

Ok, so I'm a bit stuck. I'm creating a program that has 3 classes. An object of one of the classes needs to be made up from 2 objects from one of the other classes.. and I can't figure out how to do it.

for example, if I have:

class Room{
private:
char name[];
int length;
// etc etc
public:
void some_function

and the I have..

class House{

..whos attributes are 2 'Rooms'. How would I do this?

If I try..

class House[
private:
Room 1;
Room 2;
// etc

..I get a compilation error telling me that 'Room' does not name a type!

I need to be able to send the parameters to the 'House' constructor, that will allow me to create 2 objects of type 'Room' within the class House.

Any help would be v.gratefully received!

Thanks in advance.

Recommended Answers

All 5 Replies

Would you mind posting the entire code?..

>>Room 1;
Did not you learn that variables start with alphabets and _?

>Did not you learn that variables start with alphabets and _?
How did I not notice that :).. Well spotted.

Hi - sorry, don't have the code to hand. This was a project i was working on in school. I just wanted to know if it was possible to create 2 objects of a class within the constructor of a separate class... ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.