Search code examples
c++loopsincludepragma

Including many header files together without producing errors


i have a bit of a tricky problem here. I have 3 classes: agent, campaign, and sale - and they all need to include each other, how can i do this without causing a million errors in VS, I've already tried the ifndef guard and pragma once.


Solution

  • This is way more code than I wanted to see.
    In essence, as we have said in the comments you have made everything rely on everything else which can never work.
    If you introduce a level of indirection, e.g. make an agent remember a sales id, which is an int, you won't need all headers to include all other headers. Is there a chance that an agent might make more than one sale? If you, instead of sale agent_item_sales; you could store them in a vector

    std::vector<int> agent_item_sales;
    

    However, you never use this member variable, so perhaps you can just delete it?