c++ - class with a pointer member -
class block { block *on; char *name; bool white; bool clear; bool ontable; public: block(char *nm); block(const block &ob); void setname(char *nm); char *getname() const ; bool isclear(); void setcolor(int colour); bool iswhite()const; bool isontable(); block *geton(); void puton(block &block); void putontable(); void takefromtable(); void makeclear(); void flipcolor(); void print(); };
i have class this. why declaration of *on pointer block *on? don't have write int, float or first? purpose?
block *geton() function out of class declaration this;
block *block::geton() { return on; }
i need return on pointer in code. there other way that?
block * on
declares on
pointer object of type block
. when write class definition (in case defining class block
), you're inventing a whole new datatype (in case block
), describing kind of data contains operations possible.
your geton()
code looks correct.
Comments
Post a Comment