In C++ I Cannot Grasp Pointers and Classes

后端 未结 27 1761
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 02:25

I\'m fresh out of college and have been working in C++ for some time now. I understand all the basics of C++ and use them, but I\'m having a hard time grasping more advance

27条回答
  •  隐瞒了意图╮
    2020-12-03 03:00

    Pointers are not some sort of magical stuff, you're using them all the time!
    When you say:

    int a;

    and the compiler generates storage for 'a', you're practically saying that you're declaring
    an int and you want to name its memory location 'a'.

    When you say:

    int *a;

    you're declaring a variable that can hold a memory location of an int. It's that simple. Also, don't be scared about pointer arithmetics, just always have in mind a "memory map" when you're dealing with pointers and think in terms of walking through memory addresses.

    Classes in C++ are just one way of defining abstract data types. I'd suggest reading a good OOP book to understand the concept, then, if you're interested, learn how C++ compilers generate code to simulate OOP. But this knowledge will come in time, if you stick with C++ long enough :)

提交回复
热议问题