CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2010
    Posts
    23

    virtual function question

    I had a question about base classes that have virtual functions. If we have base class shape and then there is a derive class object rectangle with additional member length.
    And we define
    shape *s= new rectangle;
    int length= s->length;
    Will this work if length is an integer and public member of derived class rectangle and shape is pure abstract class?

  2. #2
    Join Date
    Dec 2008
    Posts
    144

    Re: virtual function question

    No. It won't. The Sahpe class doesn't know anything about the length member.

  3. #3
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: virtual function question

    The concept is virtual function, and not virtual member. You cannot have data-member as virtual.
    Also, the function must be defined in base class as virtual.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured