Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ New Objects with Mulitple Classes
    primarykey
    data
    text
    <p>So I have one main file, and two classes: A display Class, and a job class.</p> <p>What I want to achieve, is for the main class to be able to call the display class, as well as interface with the job class, BUT I also want the Job Class to be able to call methods from the Display class and send parameters to the display class as well.</p> <p>I have tried multiple ways of fixing my current problem, but I have not been able to accomplish what I am wanting, I have heard about namespaces, but I am unfamiliar with them and am not sure if this is what I need.</p> <p>I have also tried to pass the Job/Display objects from main, but that has not worked with what I want to do since in my header I already end up defining a new object.</p> <p>Here is some example code of what I want to achieve (Please ignore simple compiler errors/This is just example code, and I am not going to post my entire project because that would be way to long/Ignore headers):</p> <p>Main.cpp</p> <pre><code> int main(){ Display display; Job job; job.init(); display.test(); return 0; } </code></pre> <p>Display.cpp</p> <pre><code> void Display::test(){ std::cout &lt;&lt; "testing.." &lt;&lt; std::endl; } void Display::test2(std::string ttt){ Job job; //Do not want to create a whole new object here std::cout &lt;&lt; "testing3333...." &lt;&lt; job.getThree() &lt;&lt; std::endl; std::cout &lt;&lt; "testing2222...." &lt;&lt; ttt &lt;&lt; std::endl; } </code></pre> <p>Job.cpp</p> <pre><code> void Job::init(){ Display disp2; //I do not want to create a whole new object here, but I can't fix this disp2.test2("from Job"); } std::string Job::getThree(){ return "test3"; } </code></pre> <p>Job.h</p> <pre><code>class Job{ private: Display disp; // Do not want a new object here as well public: void init(); std::string getThree(); }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload