About 'Using Forward Declarations'!

  • If we #include in a .h file we create a “chain”
  • Any .h file that includes us will in-turn include
  • This can be hard to keep track of
  • To simply use a type, we can “forward declare”
  • Simply put class ClassName; under the includes
  • You’ll still need to #include in the .cpp to use.

(Unique Video Reference: 36_BT_URC)

We would love to know…

  • What you found good about this lecture?
  • What we could do better?

Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…

  • Be in the correct forum (for the course).
  • Be in the right sub-forum (for the section)
  • Have the correct lecture tag.

Enjoy your stay in our thriving community!

2 Likes

Watching this lecture personally is confusing. Ben you mentioned without any pre-cursor (almost because you’re expecting us to know more about Unreal or programming maybe?), you say “in the tank.h it has no concept of a tank barrel…” I’m following along and i’m already confused by this stage trying to understand what you’re doing whilst watching you, but it seems you jump ahead.

Only thing I would suggest is remember some of us (including myself) are complete beginners and some patience is needed to explain WHY you’re saying what you’re saying, such as "it’s not finding this or this .h file has no concept of X. Etc.

By this stage now, it seems to be going into a deep level of programming from when we started. I hope this his constructive input :slight_smile:

Thanks for the feedback Eagle. I’ve flagged for Ben to review on his next support run :slight_smile:

Thanks for this helpful feedback, and I agree with you.

Firstly please rest assured that we’ll re-visit these topics through the course, so I’m confident it will come clear in context if you carry-on.

That said I would also like to improve this part of the course for you. I think it would be best if @sampattuzzi and I insert a video just before this one to make the whole C++ compilation process clearer. We’ve scheduled to do that.

Thank you

Ben

2 Likes

Ben and I just sat down to record a patch to help explain this better but we realise that we already have some slides on this in the previous lecture.

Is there any chance you missed that lecture? Or is it perhaps that the description there is insufficient?

I’m surprised that C++ doesn’t do more to not include a .h file that has already been included, thereby avoiding circular includes. These forward declarations feel like we are telling a computer how to do things that it should know better than we do.

In fact doesn’t the “#pragma once” prevent the same .h file being included multiple times?

No big deal though - I’ve just realised how easy it is to do forward declarations. Seems to be a very simple rule here: any .h files that you write, don’t include other .h files that you are writing - just use forward declarations instead (remembering to include the .h file that you need into your .cpp file).

Privacy & Terms