So here's a toy example of what I want:
#include <iostream>
#include <vector>
class Boss;
class Worker{
Boss& boss; // using a reference here
int salary;
public:
Worker(Boss& b, int s){
this->boss = b;
this->salary = s;
}
// other logic, whatever
};
class Boss{
std::vector<Worker> workers;
public:
// constructors, etc
Boss(){}
Worker hireSomebody(){
Worker w = Worker(*this, 25);
// I've hard coded "25" here, but assume that I do some calculations and whatnot to obtain that value.
return w;
}
};
int main() {
// Write C++ code here
std::cout << "Hello world!";
return 0;
}
I know that I can probably do it some other way (by creating a getHired() function from a worker, or something similar), but How do I do it this way?
My only requirement is that the "owner" object is "constructing" a "child" object.
ofcourse, when I try to compile this, I get something similar to invalid use of incomplete type ‘class Worker’ and return type ‘class Worker’ is incomplete