[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppGossip

(C++) Gossip

Classes I often use to determine what happens 'behind the scenes'. I have two versions: a simple one and a version you can let your class inherit from Gossip.

Simple Gossip class

  1. include <iostream>
struct Gossip { Gossip() { std::cout << "Constructor" << std::endl; } ~Gossip() { std::cout << "Destructor" << std::endl; } Gossip(const Gossip& g) { std::cout << "Copy constructor" << std::endl; } Gossip& Gossip::operator= (const Gossip& g) { if (this == &g) { std::cout << "Assigment operator: prevented self-assignment" << std::endl; return *this; } std::cout << "Assigment operator" << std::endl; return *this; } //Prefix Gossip& operator++() { std::cout << "Gossip prefix increment operator" << std::endl; ++mX; //Increment return *this; //Return class reference } //Postfix Gossip operator++(int) { std::cout << "Gossip postfix increment operator" << std::endl; Gossip old(*this); //Copy ++(*this); //Increment original using prefix return old; //Return old copy } private: int mX; };


Heritable base class

  1. include <iostream>
class Gossip { public: Gossip() { std::cout << "Contructor" << std::endl; } Gossip(const Gossip& gossip) { std::cout << "Copy contructor" << std::endl; } ~Gossip() { std::cout << "Destructor" << std::endl; } Gossip Gossip::operator=(const Gossip& other) { std::cout << "Assignment operator" << std::endl; return *this; } void gossipPublic() const { std::cout << "Gossip public" << std::endl; } protected: void gossipProtected() const { std::cout << "Gossip protected" << std::endl; } private: void gossipPrivate() const { std::cout << "Gossip private" << std::endl; } }; class GossipDerived : public Gossip { public: GossipDerived() { std::cout << "Derived contructor" << std::endl; } GossipDerived(const GossipDerived& gossip) { std::cout << "Derived copy contructor" << std::endl; } ~GossipDerived() { std::cout << "Derived destructor" << std::endl; } GossipDerived GossipDerived::operator=(const GossipDerived& other) { std::cout << "Assignment operator" << std::endl; return *this; } void gossipDerivedPublic() const { std::cout << "GossipDerived public" << std::endl; } protected: void gossipDerivedProtected() const { std::cout << "GossipDerived protected" << std::endl; } private: void gossipDerivedPrivate() const { std::cout << "GossipDerived private" << std::endl; } };


Topic links

Code links



last edited (November 11, 2006) by bilderbikkel, Number of views: 1768, Current Rev: 3 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.