Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1056321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:41:57+00:00 2026-05-16T17:41:57+00:00

$10.3/5 The return type of an overriding function shall be either identical to the

  • 0

$10.3/5

“The return type of an overriding
function shall be either identical to
the return type of the overridden
function or covariant with the classes
of the functions. If a function D::f
overrides a function B::f, the return
types of the functions are covariant
if they satisfy the following
criteria:

— both are pointers to
classes or references to classes98)

— the class in the return type of B::f
is the same class as the class in the
return type of D::f, or is an
unambiguous and accessible direct or
indirect base class of the class in
the return type of D::f

— both pointers or references have
the same cv-qualification
and the
class type in the return type of D::f
has the same cv-qualification as or
less cv-qualification than the class
type in the return type of B::f.

struct A{};
struct B : A{};

struct X{
    virtual const A * const f(){return 0;}
};

struct Y : X{
    virtual const B * volatile f(){return 0;}
};

int main(){
    Y b;
    X &r = b;
    r.f();
}

I wrote the above experimental code and find Comeau’s error/warning to be inconsitent. The warning in Line 9 seems to indicate that cv qualifier in return type is meaningless. And it is this very reason which leads to the code being ill-formed.

"ComeauTest.c", line 5: warning: type qualifier on return type is meaningless
virtual const A * const f(){return 0;}
                  ^

"ComeauTest.c", line 9: warning: type qualifier on return type is meaningless
virtual const B * volatile f(){return 0;}
                  ^

"ComeauTest.c", line 9: error: return type is not identical to nor covariant with
      return type "const A *const" of overridden virtual function function
      "X::f"
virtual const B * volatile f(){return 0;}
                           ^

So the question is, is Comeau right in giving the “warning” message at Line 9? I know that is an implementation defined behavior and Comeau is just trying to be nice. But in this case, it is at the best confusing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T17:41:58+00:00Added an answer on May 16, 2026 at 5:41 pm

    The warnings on lines 5 and 9 that the “type qualifier on return type is meaningless” are because non-class type rvalues are never cv-qualified.

    Since the result of a function that returns by value is an rvalue and a pointer is a non-class type, the returned pointer is not cv-qualified, even if the return type says that it is.

    This warning has nothing to do with covariance. The following function would cause the same warning:

    int* volatile f() { return 0; }
    

    As for the cited text from 10.3/5:

    both pointers or references have the same cv-qualification

    This is referring to the top-level qualification of the return type (that is, the volatile in const int* volatile). While the top-level qualification is meaningless, it does affect the type of the function, so given the declaration of f above, this snippet is incorrect:

    int* (*q)() = f; // error:  can't convert int* volatile (*)() to int* (*)()
    

    Likewise, if the top-level cv-qualification of the return type in the derived class member function does not match the top-level cv-qualification of the return type in the base class, the derived class member function does not override the base class member function.

    the class type in the return type of D::f has the same cv-qualification as or less cv-qualification than the class type in the return type of B::f.

    This is referring to the qualification of the class type of the return value (that is, the const in const int* volatile). This rule means that the qualification of the return type in the derived class member function must be equal to or less than that of return type of the base class member function that it overrides.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C++, a subclass can specify a different return type when overriding a virtual
How can you describe the parameters and return type (getter/setter) of your PHP functions?
I'm overriding a protected function in a subclass. Let's say I have two classes,
What return type should one return from a method that is getting rows from
Why return type of a method is not considered in method overloading ? Can
Can I use yield return when the return type is an IGrouping<TKey, TElement> or
I know that there is no return type of the constructors in C++ However,
I have a thread with return type DWORD in C but it is then
how do I find out the return type of a method from the MethodBase?
Is it possible to Marshal a generic return type as non-generic for COM interop?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.