This code took me while to figure out and a few re-reads of the explanations of each line of code for me to fully understand. Because this is new to me I don't fully understand on how and when to use the things I've been introduced to.
My question is that will it take me a while to know when and how to correctly use code? And does it come naturally to some people or is every beginner in the same boat as they learn x programming language?
Also what would be another example of use an . (dot) because I'm still not 100% confident on that.
I'm not exactly sure the proper terms for this, but it's basically a way to access the members of an object. Compare this little code to the way you use the string object:
#include <iostream>
using namepsace std;
class Data
{
public:
int number;
Data()
{
number = 0;
}
Data(int n)
{
number = n;
}
void increase()
{
number++;
}
void decrease()
{
number--;
}
};
int main()
{
Data myData01;
Data myData02(10);
cout << "myData01's number = " << myData01.number << endl;
cout << "myData02's number = " << myData02.number << endl;
myData01.increase();
myData02.decrease();
cout << "myData01's number = " << myData01.number << endl;
cout << "myData02's number = " << myData02.number << endl;
return 0;
}
If you don't know about functions, then this code probably makes zero sense.
As for your other questions. I think we're all in the same boat as far as knowing how/when to use certain C++ things. However, when I became a beginner to C++, I was already pretty strong with calculus and linear algebra which meant that I generally thought about questions in a more efficient way in the first place.