Calling class object in another class constructor

I'm trying to write a code that looks something like this:

class Foo{
...
}

....

class World{
public:
World(int a, Foo first, Foo second);
...
}


I am very new. to c++ and I cannot figure out how to make the second class use the first class in the parameter of the constructor of the second class. Any suggestions??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Foo
{
  public:
  int x;
};

class World
{
  int a;
  int b;
  public:
  World(int d, Foo first, Foo second)
  {
     a = first.x;
      b = second.x;
   }
};

int main()
{
  Foo one;
  Foo two;

  World three(7, one, two); // construtor of World object, using two Foo objects
}




Last edited on
Topic archived. No new replies allowed.