• Quatlicopatlix@feddit.org
    link
    fedilink
    arrow-up
    1
    ·
    8 days ago

    I mean in c/c++ statics arent really globals, you cant acess the from outsside their scope can you? They just retain their value or am i wrong?

    [] for arrays is the thing that has been used forever so why should we not use it annymore?

    Overloading is also pretty usefull, overloading class constructors is great. I am not a 40 year experience developer but learning c/c++ i never thought that was so bad.

    • Lojcs@lemm.ee
      link
      fedilink
      arrow-up
      1
      ·
      8 days ago

      I have no idea about c/c++ statics, does c even have statics? What kind of a scope could statics even have?

      I’m very much novice myself and I never liked the idea of trusting the compiler with figuring out the correct overload and neither do I like not being able to tell which version of a function is being called at a glance. Named constructors ftw

      • nodeluna@programming.dev
        link
        fedilink
        English
        arrow-up
        2
        ·
        6 days ago

        you can constrain functions with c++20 concepts to ensure the compiler is calling the correct function if you’re that worried

      • Quatlicopatlix@feddit.org
        link
        fedilink
        arrow-up
        3
        ·
        8 days ago

        I mean the thing with overloading is that your functions should have some difference in the paraameters they take, if you make 3 functions that have the exact same parameters of course you will not be shure what the compiler does(alötho i dont think that it would compile? But i dont think that i have ever done that)

        If you have a foo(int x float y) and a foo( int x ) function and you call it with just a x as parameter you can be shure the compiler will call your second function. If the compiler for some reasson tried to use the first foo it would throw a error because it wants a int and a float and you just gave it one int.

        I am shure that

        Foo(){ static int x =0;
        X +=1; Printf(“%d”,); }

        Foo(); every time foo is called x increments so print will be 1,2,3,4… for every call of foo

        Printf(“%d”,x); <- wont work because x cant be acessed here, it is out of scope.