It's the advice that Barjne himself and every modern book on C++ will give you. How many relevant books have you read? That kind of assignment will protect you against all type conversion errors, it is a modern feature of C++ that should always be used.
t. brainlet Just go read a book, or two or three, before giving advice online. Please, you're not good enough to be advising anyone on anything
Isaac Morales
the only time the {} list form shouldn't be used is when using auto to determine the type
James Morales
it depends.
in the case of $ int length = 100; there's nothing wrong with it, since you're just initializing the int with a literal. as soon as we get to $ int length = passed_in_from_somewhere; land, we're allowing implicit, ie information-discarding, type conversion, whereas $ int length{passed_in_from_somwhere}; will produce a compiler error when passing in a float.
however, $ std::vector vec(5, 10); and $ std::vector vec{5, 10}; do vastly different things; one creates a std::vector, size 5, all 10s, the other creates a std::vector, size 2, 5 and 10.
the latter is the reason why using curly braces for initialization isn't best practice yet. however, i tend to teach favoring curly braces while being aware of fun issues with container/class initialization.
in the end, it remains a matter of opinion. just as C++ remains a language where you still, despite all C++11 and following mitigation efforts, must know what you are doing.
William Parker
line 6 defines width and height, so when you call the AreaCube funct, it multiplies L W and H, rather than, lets say, just return length.
Jace Gray
>#include Stop coding like it's 1997. Use >#include >using namespace std; Standard C++ doesn't support iostream.h
>AreaCube(int length, int width, int height) You have to include the return type in standard C++; even in the definition after the declaration. >int AreaCube(int length, int width, int height)
It doesn't matter much and you're missing more glaring errors in OP's code.
Charles Moore
what a retard are you.
>why? why would you use c++ to write a program like that? there is no default arguments in C, you have to write 3 functions.
>at least use curly braces for fucks sake, you're not supposed to write int length = 100, but int length{100} in c++ xor yourself.
Kayden Mitchell
this is what happens when mathfags try to program
Nolan Jones
OP clearly is a CS major.
Gavin Morales
>being aware of fun issues with container/class initialization That was my point.
The language is very hard as it is and C++ is fixing old inconsistencies by introducing new inconsistencies.
Xavier Sullivan
You need to overload the function (declare the function with alternate amounts of parameters) if you want to be able to pass it with only 2 arguments. I assume you can do that in c++, Otherwise if you only pass 2 arguments you'll get unpredictable results, afaik.