Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

C++ Pointers Suck

DZone's Guide to

C++ Pointers Suck

·
Free Resource
// pointers worky


#include 
  
   

class A {
    public:
        void setMember(A& m) { this->member = &m; }

        A* member;
        int x;
};

int main(int argc, char** argv) {
    A a, b;
    a.x = 2;
    b.x = 3;
    a.setMember(b);
    b.setMember(a);
    
    std::cout << "a.member->x = " << a.member->x << "\n";
    std::cout << "b.member->x = " << b.member->x << "\n";
}

  
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}