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
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.
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
you can constrain functions with c++20 concepts to ensure the compiler is calling the correct function if you’re that worried
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.