When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
32 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
I'm currently making an object pool, and have run into a problem compiling it. class Object includes class Pool. It has a Pool& pool variable in the header so it can later call it when it needs to be put back in the pool. Pool includes Object so it can store a vector of them, as a pool does. This is giving me a lot of compiler errors, and though vague, I'm pretty sure it's because of them both requiring the other in their header like this. Assuming this is the problem, how can I fix this?
@arctic ginkgo you don't make them inside each other and use forward declarations instead
Or if you insist on making a header only thing, you use forward declaration and delay the include until appropriate
I'm not entirely sure what you mean by that.
well both solutions I suggested all mentioned forward declarations and now I'm pretty certain you don't know what those are
so arguably, learn how to use them
and what they do
that or post your actual code and I can show you concretely how forward declarations can help resolve "circular dependencies"
I know the idea is to effectively promise a method will exist before you get the proper version of it from somewhere, I just don't see how I would apply that here.
well you're already wrong here, it's not about methods/functions, it's about classes
functions can be declared and defined, likewise for variables
I meant classes.
for classes the standard terminology is forward declaration and definitions
ok well the error you describe only occurs because you have circular includes
which ties into both headers requiring the other in order to refer to the class it defines
except that you don't need the actual class definition
in at least one of the header, you typically only need to know the other class exists
and if this doesn't actually describes/matches your problem, then you're way better off just sharing your code and the compiler error
like, for real, if you aren't sure what is wrong and cannot read the compiler error, just share the compiler error
plenty of people here know how to read compiler errors
There's uh... there's a lot.
that's not the compiler error
and it doesn't matter that there are a lot
what matters is that it has information
and that experienced programmer will be able to look for the information they want inside of that
to finish this, you're looking at some error list or summary
assuming you're using visual studio, the compiler output/error can be found in the output tab/window/panel
just make sure that panel is displaying the "build output" or some such
Well that's good to know then, thanks.
I wanted to try understand the idea of fixing depedancy issues like this better in general, which I now do, and try fix these errors (partly since it's a code test) on my own, which I now can.
I think for this it makes more sense to forward declare the pool. If not I can swap it easy enough after. Thanks.
!solved