/* ** $Id: classes.cc 824 2008-03-09 19:23:52Z phf $ ** ** Similar to structs.cc, shows that we can add "methods" ** to either structs or classes. :-) */ #include struct xyz { int a; int b; // public by default xyz(): a(1), b(2) {} // constructor int plus() { return a+b; } // method }; class XYZ { int a; int b; // private by default public: XYZ(): a(3), b(4) {} // constructor int plus() { return a+b; } // method }; int main() { xyz x; XYZ y; x.a = 10; x.b = 1; // y.a = 20; // not accessible std::cout << x.plus() << std::endl; std::cout << y.plus() << std::endl; }