DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

C++ Pointers Suck

02.24.2008
| 2636 views |
  • submit to reddit
        // 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";
}