Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
deleted 2 characters in body
Source Link
4386427
  • 44.7k
  • 4
  • 44
  • 69

This answer will not discuss the overall interface design (i.e. whether it's good or not). The answer is based on the design already selected by OP.

Do I do #include "leds.h" in my modbus.h or modbus.cpp?

If nothing in modbus.h requires knowledge of the stuff in leds.h, you do the include in modbus.cpp. Otherwise, in modbus.h

Is there any difference?

When you do the include in modbus.h, all users of "modbus" will also "know"know about "leds". If they don't need that information, there is no reason to give it to them.

Further, it may slow down compilation when you include unnecessary files in a compilation unit.

I must then declare the colours that I will be using in my modbus as extern such as extern RgbColor blue;. And again, my concern whether it should be declared in modbus.h or modbus.cpp.

Neither. The extern declations should go into leds.h

This answer will not discuss the overall interface design (i.e. whether it's good or not). The answer is based on the design already selected by OP.

Do I do #include "leds.h" in my modbus.h or modbus.cpp?

If nothing in modbus.h requires knowledge of the stuff in leds.h, you do the include in modbus.cpp. Otherwise, in modbus.h

Is there any difference?

When you do the include in modbus.h, all users of "modbus" will also "know" about "leds". If they don't need that information, there is no reason to give it to them.

Further, it may slow down compilation when you include unnecessary files in a compilation unit.

I must then declare the colours that I will be using in my modbus as extern such as extern RgbColor blue;. And again, my concern whether it should be declared in modbus.h or modbus.cpp.

Neither. The extern declations should go into leds.h

This answer will not discuss the overall interface design (i.e. whether it's good or not). The answer is based on the design already selected by OP.

Do I do #include "leds.h" in my modbus.h or modbus.cpp?

If nothing in modbus.h requires knowledge of the stuff in leds.h, you do the include in modbus.cpp. Otherwise, in modbus.h

Is there any difference?

When you do the include in modbus.h, all users of "modbus" will also know about "leds". If they don't need that information, there is no reason to give it to them.

Further, it may slow down compilation when you include unnecessary files in a compilation unit.

I must then declare the colours that I will be using in my modbus as extern such as extern RgbColor blue;. And again, my concern whether it should be declared in modbus.h or modbus.cpp.

Neither. The extern declations should go into leds.h

Source Link
4386427
  • 44.7k
  • 4
  • 44
  • 69

This answer will not discuss the overall interface design (i.e. whether it's good or not). The answer is based on the design already selected by OP.

Do I do #include "leds.h" in my modbus.h or modbus.cpp?

If nothing in modbus.h requires knowledge of the stuff in leds.h, you do the include in modbus.cpp. Otherwise, in modbus.h

Is there any difference?

When you do the include in modbus.h, all users of "modbus" will also "know" about "leds". If they don't need that information, there is no reason to give it to them.

Further, it may slow down compilation when you include unnecessary files in a compilation unit.

I must then declare the colours that I will be using in my modbus as extern such as extern RgbColor blue;. And again, my concern whether it should be declared in modbus.h or modbus.cpp.

Neither. The extern declations should go into leds.h