Okay I'm just wondering what is the point of "class". I mean, the guy doesn't really tell much about classes. I know the difference between class and struct is that struct is public by default and class is private by default.
But since in C++ Console Programming you cannot change the values of anything inside private functions, why the hell would you even put it?
Also, if you put "class", then everything will be unchangeable... What's the point?
Like if you do:
Code:
class MPGH
{
a=0
b=0
c=0
d=0
};
You can't change anything in there, like you cant do this all of a sudden..
Code:
class MPGH
{
a=0
b=0
c=0
d=0
};
int main()
MPGH Box
Box.a=2
*I know the code is wrong it's just an example guys*
Members of a class are private by default, whereas members of a struct are public by default. Inheritance between classes is also private by default, and inheritance between structs is public by default.
There you go.
Originally Posted by master131
There you go.
That didn't help at all. Could be my misunderstanding, but I'm asking like why you need it, because you need to change the variables somewhere within your code sometime, and especially pointers.
A young monk, new to the temple, not only declared all his methods public but all his instance variables as well. The head abbot grew weary of rebuking the monk and asked the Java master for advice.
The next day, the master summoned the monk to take lunch with him in his private office.
The monk entered to find a sumptuous meal laid out upon the conference table. The master then bade the monk to lie upon the floor.
The monk did as commanded, whereupon the master opened the monk’s robes and drew a large knife. He pressed the naked point firmly into the monk’s chest until a ruby droplet welled up around the blade. The monk cried out in terror and asked the master what his intention was.
“To slit open your belly,” explained the master, “so that I may spoon the rice and pour the tea inside. My schedule is quite full, and I find this method of feeding guests to be extremely efficient.”
Dude how the hell does this relate to my thread topic?
Stop spamming.
Originally Posted by Infractured
Dude how the hell does this relate to my thread topic?
Stop spamming.
That relates incredibly to this topic. In classes, you generally have getter and setter methods inside the class. The getter methods get the value of internal variables. The setter method sets the value of internal variables. This means that no unwanted and unregulated change can happen to internal variables. This is the answer to your question, as abstractly explained by both the story, and the quote. You keep things private so that it can only be changed in a way that will not produce any errors, and will be able to have bad input handled accordingly.
Originally Posted by ғᴜᴋᴏᴊʀ
That relates incredibly to this topic. In classes, you generally have getter and setter methods inside the class. The getter methods get the value of internal variables. The setter method sets the value of internal variables. This means that no unwanted and unregulated change can happen to internal variables. This is the answer to your question, as abstractly explained by both the story, and the quote. You keep things private so that it can only be changed in a way that will not produce any errors, and will be able to have bad input handled accordingly.
Wow thank you very much for helping me out. That pretty much answered my question accordingly.
Close @Hassan
Not only that, but classes also help to superimpose the way a human sees the world over how the computer sees the world. The computer does not know what a car is, and why a car needs gas the operate. Via classes you can make the computer 'pretend' it knows how stuff works. So then you can encapsulate the 'computer' side of things (calculations, iterations that sort of thing). The result is that you can use a class as if you were actually dealing with cars and gas, instead of numbers, strings and hashes.
In short this is called OOP or object oriented programming, the practice of approaching a problem in a way that is easy for humans to understand, while neatly encapsulating and abstracting the computer logic to a point where it simulates a limited part of how things work in the real world. You think in terms of objects, cars, gas, boxes, buildings and people. To solve problems like:
Transport 100 people from building a to building b using 10 cars that have 100 gallons of gas.
Finally classes are just very handy to keep code clean, everything is neatly tucked inside a class in an organised fashion.
And that's why classes are used.
Originally Posted by Infractured
Dude how the hell does this relate to my thread topic?
Stop spamming.
> Knows nothing about what he's talking about, is asking for help.
> Refuses to accept answers, says they are wrong.
stronglogic/10.
Originally Posted by Broderick
> Knows nothing about what he's talking about, is asking for help.
> Refuses to accept answers, says they are wrong.
stronglogic/10.
Dude. At first I thought the story he just gave me completely did not match the thread point topic. Yes, I read it twice, it was just about a monk. How does that relate to classes and struct? I'm talking about C++ here. This was why I thought he was spamming, because his answer was completely beyond my point.
And am I refusing answers? No. The answer he gave me at first I thought it was wrong and completely out of topic, so that's why I questioned him.
If you knew how that compared to my point, then you could have just explained to me. Did you really have to write that out? I can see you have no friends. Just call yourself an ignorant fucker, because you ARE one.
no answer yet?
anyway u must make those members public as they are private by default
use this:
Code:
class MPGH
{
public:
//member declaration
Originally Posted by Infractured
Dude. At first I thought the story he just gave me completely did not match the thread point topic. Yes, I read it twice, it was just about a monk. How does that relate to classes and struct? I'm talking about C++ here. This was why I thought he was spamming, because his answer was completely beyond my point.
And am I refusing answers? No. The answer he gave me at first I thought it was wrong and completely out of topic, so that's why I questioned him.
If you knew how that compared to my point, then you could have just explained to me. Did you really have to write that out? I can see you have no friends. Just call yourself an ignorant fucker, because you ARE one.
Obviously the story was a metaphor lol. Yes, I'm the ignorant one, kthnxbai.