[Solved] Pass Object to Class via Constructor [closed]


Your code is not working because:

  • You need a semicolon after the declaration of a class
  • static is not a valid type
  • static objects have to be initialized outside of their definition in the class in order to be used elsewhere in the code. You need something like: Fred Fred::sharedFred; before main
  • Declaration of a function must have () in front of the function name before the {} braces
  • the classes have to be in the scope of main function for them to be used, and also in the scope of each other depending on what is calling what. i.e. main has to be declared after the class and same for each class that calls another
  • Properties/methods declared in a class are private by default. To make group of properties/methods public, have the keyword public followed by a colon at the top of the group

1

solved Pass Object to Class via Constructor [closed]