CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: C++ programming

  1. #1
    Join Date
    May 1999
    Posts
    1

    C++ programming

    Hi all,

    I have a question about C++ standard. According to [Stroustrup, C++ Programming Language, 3d ed., p.425], there is one case when the return type of overriding function may differ from the virtual function it overrides. Namely, if the original return type was B*, then the return type of the overriding function may be D*, if B is a public base of D.

    In my programm I have three classes,

    class Base
    {
    ...
    virtual Base* f() { return 0; }
    ...
    }

    class Derived1: public Base
    {
    ...
    }

    class Derived2: public Derived1
    {
    ...
    Derived2* f() {...}
    ...
    }

    According to the standard (as far as I understand it), this should work. However, the Microsoft Visual C++ 6.0 compiler throws me error C2555. Where the truth?

    Thank you for help,
    Ilia.



  2. #2
    Join Date
    Apr 1999
    Posts
    16

    Re: C++ programming

    Baby, you override the virtual function,
    What you do is not deriving the fuction,
    but is overriding.Check the parameters,
    return value please.


  3. #3
    Join Date
    Apr 1999
    Posts
    383

    Re: C++ programming

    You are correct in thinking this should work. This feature is known as 'covariant return types', and has been in the standard for quite some time. It is extremely useful, especially when writing clone functions for polymorphic objects, but Microsoft have so far been unable or unwilling to support it in VC++.

    Unfortunately, it is just another example of VC++6.0's lack of standard compliance :-(

    You will have to work around it as best you can.

    Dave


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