How do you keep it all straight?

The challenge in this video stuck me over stupid stuff.


At this point, I’m getting even basic syntax screwed up because I cant keep this stuff straight in my head.

Prop.h
#include "raylib.h"


class Prop
{
public:
    Prop(Vector2 Pos,
        Texture2D Tex);
    void Render(Vector2 KnightPos);

private:
    Texture2D Texture{};
    Vector2 WorldPos{};
    Vector2 ScreenPos{};
    float Scale{4.f};

};
Prop.cpp
#include "Prop.h"
#include "raylib.h"
#include "raymath.h"

Prop::Prop(Vector2 Pos, Texture2D Tex) : WorldPos(Pos),
                                         Texture(Tex)
{
    {
        void Render(Vector2 KnightPos)
        ScreenPos = Vector2Subtract(WorldPos, KnightPos);
        DrawTextureEx(Tex);
    }
};

We’ve got three different files talking to each other. He’s making stuff in one, saying how it works in another, and actually using the thing in a third. This is confusing and frustrating, how do you keep it sorted what goes where, let alone the arcane details that must be observed when writing it? Is it maybe because he’s lightened up on the strong metaphors and jokes that the class began with or am I just tired?

Further, after following along with the answer I’m able to get a good result but I still get these warnings.
warnings

Finally, it occurs to me that previously he made it sound like a big deal that we UnloadTexture() for all images we use but it seems we did no such thing with rock.

1 Like

The lack of UnloadTexture() was an accidental oversight. For a small project like this it’s not really a big deal but for larger projects you’ll want to keep an eye on it for memory management.

Those warnings are because the list used to initialize the member variables in the constructor don’t match the order they are declared in the header. This does get addressed in a later lecture, I believe.

As for keeping track of it all, it takes practice and each programmer has their own method.

3 Likes

Okay, more specific question. Why does he need to “Fully Qualify” Render() when it’s being written in the Prop.cpp file? What is this scope resolution operator doing?

1 Like

When I inconsistently need a ; after the } the syntax really throws me. With scrutiny, I see these circumstances are when complex declarations are being spread out over multiple lines but it keeps throwing me.

1 Like

The major times it’s needed are when you declare a class, struct, or enum. Otherwise you generally don’t need a semi-colon after a bracket.

2 Likes

A few lessons later I came across this post and what he had explained in the earlier video finally clicked.

To prevent trouble the sequence of the initialized variables must match the sequence they get declared in. The compiler is trying to say I’d simply overlooked this detail.

I now have 7 files and special messages to the compiler that prevent double-including header files. This lesson doesn’t get easier. Find the speed controls because it starts to move even faster but persistence and repetition give things more time to sink in.

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms