I am a beginner, have read articles, but do not fully understand a real given example or reason as to one why one would need to use classes or vectors.
I would appreciate if some one could give an example of its use, in at least two different ways/programs or functions.
Thank you! :)
(also I'm a little confused with pointers and inheritance, encapsulation and such)
About classes (which is a core part of object-oriented programming): I hear it's supposed to make code reusable and programs more manageable and maintenance friendly, easier to change/add/remove/test/update and make things more structured etc.
I personally find it a stick in my ass because I'm too used to procedural and functional programming.
Also, pointers are evil.
(Note: Take the last two lines with a grain of salt).
I personally find it a stick in my ass because I'm too used to procedural and functional programming.
Use it only when necessary or when the project is huge else I feel the amount of time going into the program design is quite time consuming.
Instead of inheritance, try composition which I feel easy to grasp and also easy to read the code workflow too :P
PS I know the has-a and is-a relationship differences but I like to 'twist' their meaning to facilitate me easier code maintenance in future hahaha....
Also, pointers are evil.
Use it only when necessary aka sparingly and it does wonders for me personally.
Explain a use in which pointers may be fully necessary. I still have yet to see a reason why they'd need any use with any program I'd come up with, large or small.
Explain a use in which pointers may be fully necessary. I still have yet to see a reason why they'd need any use with any program I'd come up with, large or small.
Say you need to interface with a vendor library and their interface is C-based which mean when you call their API you are supposed to pass in pointers else you cannot interface with them at all.
I would allow other forum-ers to say other situations.
Say you need to interface with a vendor library and their interface is C-based which mean when you call their API you are supposed to pass in pointers else you cannot interface with them at all.
Could you explain that, or any one, but in a less technical way? Sorry, but I can't fully understand what sohguanh meant.
Let me give an example. In the commercial software world, usually we don't do *EVERYTHING* from scratch as it will be too time consuming and our time to market schedule breached. That is why for certain application functionalities we look for other commercial vendor libraries. Those vendor only provide C-based API and you got no choice but to pass pointers into their API.
I don't know if you are a software developer but maybe someone else in this forum can give you a less technical reason.
I don't know if you are a software developer but maybe someone else in this forum can give you a less technical reason.
I am not a software developer. lol
I'm "FAR" from that.
And yes, a less technical explanation would be more helpful because I don't have such a level of knowledge with programming to understand the way you implement it in.
I'm still green, but I've been under the impression lately that pointers is a tool used for handling memory in C++ which is supposedly a powerful thing if used correctly.
And yes, a less technical explanation would be more helpful because I don't have such a level of knowledge with programming to understand the way you implement it in.
Ok I think of an analogy. You have a very old computer which uses PS2 port to plug your mouse in. One day it is spoilt and you go shopping for a new mouse. But you didn't check the interface so you bought a USB port mouse. You went home you discover you cannot plug the USB mouse into your PS2 port and you frown. Btw PS2 hole is round whereas USB hole is flat and rectangular so they don't fit each other.
So the idea is same, the vendor sell us C-API, we have no choice but to call them using the pointers notation they request us to pass in.
Program: Please enter your student's names.
User A: <enters seven names>
User B: <enters fifty names>
A program that expects the same input every time is not very useful. Any form of database whatsoever absolutely requires the ability to handle an unknown (even if bounded) amount of data.
This kind of stuff can still be done without things like classes and vectors, but it sure is easier with them, because they reduce the amount of bookkeepping you have to do to maintain your variable amount of data.
Suppose you have two strings in memory that you may wish to display. The first string is, "Good job!" You plan to use it if the user did the right thing. The second is, "Whoops! You made a mistake. Try again!" You plan to use this if the user erred.
The strings cannot be in the same place in memory, obviously, because they are different. The function to display a string, however, cannot be useful unless it can display different strings -- otherwise the computer could only tell you one single thing -- and that would be pretty useless.
So, functions like puts() take as argument the address of the first character in the string to display. If the user does the right thing, I can pass the address of the first string. If the user goofed up, I can pass the address of the second.
Without the ability to use a pointer to the correct string to display, I could not tell the user anything useful.
Variations, like copying a string from one place in memory to another, just shift the addressing from the print function to the copy function. In every case, you must have the ability to address the string.
On an even lower level, all memory is just a great big array of data. Your program variables are in specific spots in that array. How does your program know the difference between your variables? Because it knows where they are in the array -- that is, it knows their address.
It does help, but I still find it far too advanced to even nudge any thing off of. Actually, I find it so hard to the point where I can't barely begin to even think of how to use it and where/why to in a program I'd make.
There is always garbage collection programming language like Java, Perl, Python etc which does not require you to do any dynamic memory management aka NO pointers needed.
Maybe you should look at those programming languages instead.
There is always garbage collection programming language like Java, Perl, Python etc which does not require you to do any dynamic memory management aka NO pointers needed.
Well, if it involves pointers it's garbage as a whole. So yeah thanks for telling me which of the programming languages are actually functional rather than just dynamic. :)