I’ve never even been on a slack channel, let alone the C++ one.
About what I would have expected.
To be honest I think it makes sense to learn full C++ alongside Arduboy.
I started using the Arduboy after I’d learnt C++ and I probably found it a lot easier because of that.
Hopefully my explanation of the compilation process will make it clear why things are this way.
For the record, file names are completely arbitrary.
The compiler doesn’t consider
fish.cpp to be related, it’s only what you write that makes them related.
Anything can be defined without being declared because a definition is also a declaration, but you can’t declare something unless it’s also defined somewhere.
I’m not sure what you mean by this.
Do you mean how to declare something and have its definition elsewhere?
In most cases you don’t need to do this, you can just define everything in the same header that the thing is declared in.
You don’t even necessarily need to have any
You probably don’t want to do this because the values of the
enum class are just as important as the type itself.
Declaring the type doesn’t give you access to its values, so you want to be defining it in a header and then including that header when and where the type is needed.
That said, you can predeclare with
enum class name;,
or if you’re specifying the size of the enum as well then
enum class name : type; (e.g.
enum class EntityType : uint8_t;).
But like I say, you shouldn’t need that, because having access to the type doesn’t give you access to the values.
Again, this is something you probably don’t want to be doing because only having knowledge of the type doesn’t give you knowledge of the class’s members.
In fact, if you only know the type exists, you can only use pointers and references to the class, you can’t even declare a function argument of the class type (because without the definition the compiler doesn’t know how big the type is).
This can be done with
This one’s a bit more common, where you declare the methods in the class definition but don’t implement them in the header file, you just implement in the
That would be like:
int getValue() const;
void setValue(int value);
int SomeClass::getValue() const
void SomeClass::getValue(int value)
this->value = value;
Every file exists in isolation.
If a file needs to know the existance of a type that’s declared or defined in a different header, it must include that file.
.cpp files are a slight exception to this rule.
If a function is defined in a
.cpp file then only the declaration needs to be known.
For types, you almost always want to see the full definition because it’s important for knowing the size and members of the type (this is true for
enum class (and another thing I won’t tell you about because it will complicate matters)).
If you want to define it in a header:
inline int get2Squared()
return 2 * 2;
If you want a separate declaration and definition:
return 2 * 2;
Yes. As I say, any file that wants to ‘see’ something must include the declaration/definition.
Includes aren’t something to be afraid of, they’re the natural way of being aware of something’s existance.
I’ll get round to doing that at some point.
The only thing that puts me off is that I’d be worried about all the experienced programmers getting into arguments over biases, nuances and pedantry.
Probably the best bit of advice I could give you:
Forget (almost) absolutely everything you learned in gamemaker.
GML is a terrible language created by a novice who never studied language theory and it has very little in common with ‘real world’ languages.
I’ve never got round to reading it, but it comes up a lot.
Yep. Sometimes these rules have more than one purpose/reason.