Strange class definition

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • seema

    #1

    Strange class definition

    I am new to C++ programming, can somebody explain what is this
    me_xx is it a type name or instantiation of class Final. And also
    how to use me_xx ?
    struct IViewObjectEx
    {

    public:
    void solv()
    {
    }

    };

    class XViewObject : public IViewObjectEx {

    public:
    virtual void Draw()=0;

    };

    class Final: public XViewObject
    {
    public :
    void Draw(){
    cout <<"Drawing thru Draw()"<<endl;
    }

    } me_xx;

    int main(){
    Final pre;
    }

    Thanks in advance,
    Seema

  • Victor Bazarov

    #2
    Re: Strange class definition

    seema wrote:[color=blue]
    > I am new to C++ programming, can somebody explain what is this
    > me_xx is it a type name or instantiation of class Final. And also
    > how to use me_xx ?[/color]

    It's an instance. It's like this: C++ allows to define a class with or
    without declaring something in the same statement. In actuality those
    are two separate grammar constructs, IIRC, but they look very similar.

    IOW, you can write

    struct A {}; // class definition

    or

    struct A {} a; // class definition _and_ an object declaration

    Use 'me_xx' just like you would any other object of type 'Final'.
    [color=blue]
    > struct IViewObjectEx
    > {
    >
    > public:
    > void solv()
    > {
    > }
    >
    > };
    >
    > class XViewObject : public IViewObjectEx {
    >
    > public:
    > virtual void Draw()=0;
    >
    > };
    >
    > class Final: public XViewObject
    > {
    > public :
    > void Draw(){
    > cout <<"Drawing thru Draw()"<<endl;
    > }
    >
    > } me_xx;
    >
    > int main(){
    > Final pre;
    > }
    >
    > Thanks in advance,
    > Seema
    >[/color]

    V
    --
    Please remove capital As from my address when replying by mail

    Comment

    Working...