Was it only unintuitive to me?

A long time ago I read Disch's famous article:
http://www.cplusplus.com/forum/articles/10627/

Fast-forward to today and I find out something completely unintuitive that I honestly believed didn't work:
http://ideone.com/rI2ukX

For a long time now I have been structuring my code in a way to avoid this, but it turns out it was never a problem after all. I'm going to have to go through and simplify my code now that I know this is possible (because my workarounds are needlessly overcomplicated).
Last edited on
References are not include dependencies, so forward declaring works in that case.

It only becomes an include dependency when you need to access one of its members and/or know the size of it.
closed account (Dy7SLyTq)
you didnt know you could do that? isnt that the basis for a link list class/struct? declaring a pointer or reference to said class or struct before its finished, as long as you dont try to manipulate it?
@Disch: but all examples about include dependencies only use pointers, so I was left to make assumptions about references.

@DTSCode: As I said to Disch, I had different ideas in my head for pointers and references regarding include dependencies.
From that article, point 4 The "right way" to include
> forward declare B if: A contains a B pointer or reference
> forward declare B if: one or more functions has a B object/pointer/reference as a parementer, or as a return type

There was no assumptions to made
You should still avoid writing code like that if you can. The way it's written there it's just as useful as a void pointer.
The way it's written there it's just as useful as a void pointer.


? How do you figure?

void pointers are 'bad' because they're not typesafe. A pointer to an incomplete type is still typesafe, you just have to complete the type before you can dereference it.
I was talking about it's utility, not best practices. In both cases you can't do much with either one without more data, in the case of a void pointer it needs to be cast and in this case you need someway to tell the program what 'A' actually is.
thanks for the reference to an article I never knew I needed to read, bookmarked that, I avoided header files and therefore their problems for too long, and im not happy about coding in other languages, I dont feel like im doing anything just putting bits together.
ne555 wrote:
From that article, point 4 The "right way" to include
> forward declare B if: A contains a B pointer or reference
> forward declare B if: one or more functions has a B object/pointer/reference as a parementer, or as a return type

There was no assumptions to made
You're right, I misread the article when I first read through it - maybe I took 'reference' not to mean an actual C++ reference.

@Computergeek01: I actually work with an SDK for DLLs where there is an incomplete type, and I use the value of pointers to it to differentiate between different open files in the program editor. It's not well documented and I had to take a guess and ask the developers about it, and my guess was right. If it had been only a void pointer I would have ignored it and would have been unable to achieve my goal.
Last edited on
An SDK for DLL's? You mean the WinAPI?
I guess I said it in a really redundant way, but what I meant is that the SDK lets the DLL interface with the software properly. And no it's not the WinAPI ;p
Last edited on
Topic archived. No new replies allowed.