Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

c++ pointers suck (See related posts)

// pointers worky

#include <iostream>

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";
}

You need to create an account or log in to post comments to this site.


Click here to browse all 7284 code snippets

Related Posts