• 0 Posts
  • 20 Comments
Joined 1 year ago
cake
Cake day: June 30th, 2025

help-circle



  • It was a simplified example.

    B and C can’t share any other attributes without duplication of code

    struct A {
        [[nodiscard]] virtual std::uint32_t DoSomething() = 0;
    };
    
    struct B : A {
        std::uint32_t DoSomething() override { 
            return 0;
        }
    };
    
    int main() {
        B b;
        b.DoSomething(); //no warning
    }
    

    even if you use virtual attributes aren’t inherited.

    If you ment members instead of attributes this is unrelated to virtual:

    struct A {
        std::uint32_t a;
    };
    
    
    struct B : A {
        void DoSomething() { 
            std::println("B"); 
        }
    };
    
    struct C : A {
        void DoSomething() { 
            std::println("C"); 
        }
    };
    

    Now the member is shared and it works fine and there is no virtual.

    There’s also no strict enforcement of inheritance.

    True, but neither is there when just using virtual:

    struct A {
        virtual void DoSomething() = 0;
    };
    
    struct B : A {
    
    };
    

    This compiles fine if final is not added.

    Not that its an issue as reflection has solved this problem:

    consteval std::string_view HasMethods(std::meta::info impl, std::meta::info iface) {
        constexpr auto ctx = std::meta::access_context::unchecked();
        for (auto fn : members_of(iface, ctx)) {
            if (!is_function(fn) || is_special_member_function(fn)) continue;
            bool found = false;
            for (auto cand : members_of(impl, ctx))
                if (is_function(cand) && has_identifier(cand) && identifier_of(cand) == identifier_of(fn) && type_of(cand) == type_of(fn))
                    found = true;
            if (!found)
                return std::define_static_string(std::string(identifier_of(impl)) + " is missing " + display_string_of(fn));
        }
        return {};
    }
    
    
    struct A {
        void DoSomething();
    };
    
    struct B  {
    
    };
    static_assert(HasMethods(^^B, ^^A).empty(), HasMethods(^^B, ^^A));
    
    // g++ -std=c++26 -freflection main.cpp
    // main.cpp:30:41: error: static assertion failed: B is missing void A::DoSomething()
    // 30 | static_assert(HasMethods(^^B, ^^A).empty(), HasMethods(^^B, ^^A));
    

    Now you get the strict enforcement of inheritance and no virtual.


  • Why does it make zero sense in C++?

    edit: simplified example of what i mean

    struct A {
        virtual void DoSomething() = 0;
    };
    
    struct B : A {
        void DoSomething() override { 
            std::println("B"); 
        }
    };
    
    struct C : A {
        void DoSomething() override { 
            std::println("C"); 
        }
    };
    
    void InvokeDoSomething(A* a) {
        a->DoSomething();
    }
    

    vs

    struct B {
        void DoSomething() { 
            std::println("B"); 
        }
    };
    
    struct C {
        void DoSomething() { 
            std::println("C"); 
        }
    };
    
    template <typename T>
    void InvokeDoSomething(T* t) {
        t->DoSomething();
    }
    








  • It depends, do you want to learn or do you want to get something fast and don’t care how?

    If you want to learn don’t let AI write anything. Ask it questions if you don’t understand, ask it to explain, but wrte everything yourself.

    If you want to get something that works and don’t care how, make extensive tests. Use a minimum test coverage. Automaric AI reviewing the PR of the AI, And keep the agent going until it passes the CI.

    To awnser your question specifically read the plans very carefully. Most of the time the agents execute the plan fairly faithfully, you don’t need to correct the code much if you make sure to read the initial plan very carefully and make changes on where it made a mistake.

    This does build on the fact that you can actually understand what its writing, if you can’t, go with the first approach and don’t use AI at all for writing code.



  • Either the UI is defined in some DSL, that’s loaded (or compiled) and then you spend most of the time writing getElement(pathToElement) and wiring it up, or you have to boilerplate create each element and parent.addChild(element).

    Im saying “there are no elements” because of what OP says here, the system i’m using now doesn’t have that.

    You have a panel+border+text “primitive” drawing functions. Nothing is stopping you from creating a single function that calls all 3 of those. You probably should, since it’s probably a common pattern. You could call it DrawBoxedText. There is no difference between a DrawBoxedText function and a BoxedText element with a draw() method.

    yeah i could make a function for that, but i would argue that “here is no difference between a DrawBoxedText function and a BoxedText element with a draw() method.” there is a big difference between these. Personally i find using a function like DrawBoxedText much easier.


  • I had my own library for UI that tried to have a element model, but it was bloated and didn’t scale well. Now im drawing everything via vulkan compute shaders and its fast and looks great.

    I think the philosophy needs to switch from elements back to pixels, atleast that is what worked for me.

    i dare to say its as easy as webdev

    snippet from my game:

    DrawMenuButton(buf, btnExit, "Exit to title", exitHover, exitHover && window.mouseLeftHeld, false, font, topFontPx, exitCol);
    DrawMenuButton(buf, btnSave, "Save changes", saveHover, saveHover && window.mouseLeftHeld, false, font, topFontPx, saveCol);
    PushPanel(buf, titleRect, panelBgColor, 6.0f * s);
    PushBorder(buf, titleRect, borderColor, 6.0f * s, 1.5f * s);
    DrawText(buf, "OPTIONS", titleRect.x + titleRect.w * 0.5f, titleRect.y + titleRect.h * 0.5f + topFontPx * 0.32f, font, topFontPx, textUnfocusedColor, TextAlign::Center);
    

    this is in the draw function, and along with the other code produces this menu:


  • why the industry is still not ready to move away from it.

    But why should the industry move away from it?

    Am i the only person on earth who doesn’t think C++ is a liability and actuallly works faster in it?

    At work i have to develop a backend api in TypeScript and it severly lacks in features compared to C++, again maybe its just me but i don’t find how one is expected to magically program faster in TypeScript then C++.

    Not to mention the idiocy of compiling a static typed language to a dynamic typed language which is then interpreted.