In C++ I Cannot Grasp Pointers and Classes

后端 未结 27 1795
隐瞒了意图╮
隐瞒了意图╮ 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 02:38

    Pretend a pointer is an array address.

    x = 500; // memory address for hello;
    MEMORY[x] = "hello"; 
    print  MEMORY[x]; 
    

    its a graphic oversimplification, but for the most part as long as you never want to know what that number is or set it by hand you should be fine.

    Back when I understood C I had a few macros I had which more or less permitted you to use pointers just like they were an array index in memory. But I've long since lost that code and long since forgotten.

    I recall it started with

    #define MEMORY 0; 
    #define MEMORYADDRESS( a ) *a;
    

    and that on its own is hardly useful. Hopefully somebody else can expand on that logic.

提交回复
热议问题