+ 1
About class constructors (CPP)
I'm now on the stage that explains work with constructors. I implemented something like a constructor in my little project. Actually, in "real life" I wouldn't do it (use class) in the code like that but I need experience using constructor. The code works like it is but frankly speaking I do not understand why I declared this constructor that way and why I should input same data twice in lines 71 and 72. I am really confused. Could anybody briefly explain how I can correctly use constructors in my case or at least refer me in right way? Thanks. https://code.sololearn.com/c8A8S6Km5rK4
4 Respostas
+ 2
Why not just use the class' private variables in the function(s), which you already provided through the constructor, instead of providing them again in the function parameters?
The question, for you, is more like should windDir call windSpeed to get the value of tws, or should the user do it and provide the argument?
1 might be an optimization option, the other easier to use?
+ 1
CeePlusPlus,
It was clear that I had to give some data to a function. I was confused why I couldn't awoid entering the same data in line 71. Looks like it isn't a problem of lines 71 and 72 but of the lines where I declare the class and its constructor in the beginning.
+ 1
@Dimitriy Sychov
You had to enter the same data in line 71 because you made the constructor have some parameters to input. Also, you can do what @Dennis said, use the class's private variables for the function(s).
0
You have to input the same date in line 72 because the function requires parameters.