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 678075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:06:33+00:00 2026-05-14T01:06:33+00:00

[All of the following was tested using Visual Studio 2008 SP1] In C++, const

  • 0

[All of the following was tested using Visual Studio 2008 SP1]

In C++, const qualification of parameter types does not affect the type of a function (8.3.5/3: "Any cv-qualifier modifying a parameter type is deleted")

So, for example, in the following class hierarchy, Derived::Foo overrides Base::Foo:

struct Base
{
    virtual void Foo(const int i) { }
};

struct Derived : Base
{
    virtual void Foo(int i) { }
};

Consider a similar hierarchy in C++/CLI:

ref class Base abstract
{
public:
    virtual void Foo(const int) = 0;
};

ref class Derived : public Base
{
public:
    virtual void Foo(int i) override { }
};

If I then create an instance of Derived:

int main(array<System::String ^> ^args)
{
    Derived^ d = gcnew Derived;
}

it compiles without errors or warnings. When I run it, it throws the following exception and then terminates:

An unhandled exception of type ‘System.TypeLoadException’ occurred in ClrVirtualTest.exe

Additional information: Method ‘Foo’ in type ‘Derived’…does not have an implementation.

That exception seems to indicate that the const qualification of the parameter does affect the type of the function in C++/CLI (or, at least it affects overriding in some way). However, if I comment out the line containing the definition of Derived::Foo, the compiler reports the following error (on the line in main where the instance of Derived is instantiated):

error C2259: ‘Derived’: cannot instantiate abstract class

If I add the const qualifier to the parameter of Derived::Foo or remove the const qualifier from the parameter of Base::Foo, it compiles and runs with no errors.

I would think that if the const qualification of the parameter affects the type of the function, I should get this error if the const qualification of the parameter in the derived class virtual function does not match the const qualification of the parameter in the base class virtual function.

If I change the type of Derived::Foo‘s parameter from an int to a double, I get the following warning (in addition to the aforementioned error, C2259):

warning C4490: ‘override’: incorrect use of override specifier; ‘Derived::Foo’ does not match a base ref class method

So, my question is, effectively, does the const qualification of function parameters affect the type of the function in C++/CLI? If so, why does this compile and why are there no errors or warnings? If not, why is an exception thrown?

  • 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-14T01:06:34+00:00Added an answer on May 14, 2026 at 1:06 am

    Well, it’s a bug. The const modifiers is emitted into the metadata with the modopt custom modifier. Unfortunately, the C++/CLI language rules do not match the CLI rules. Chapter 7.1.1 of the CLI spec says:

    Custom modifiers, defined using modreq
    (“required modifier”) and modopt
    (“optional modifier”), are similar to
    custom attributes (§21) except that
    modifiers are part of a signature
    rather than being attached to
    adeclaration. Each modifer associates
    a type reference with an item in the
    signature.

    The CLI itself shall treat required
    and optional modifiers in the same
    manner. Two signatures that differ
    only by the addition of a custom
    modifier (required or optional) shall
    not be considered to match. Custom
    modifiers have no other effect on the
    operation of the VES.

    So, the CLR says that Derived::Foo() is not a override, C++/CLI says it is. The CLR wins.

    You could report the bug at connect.microsoft.com but it probably a waste of time. I think this incompatibility was intentional. They should have changed the language rules for C++/CLI but surely thought C++ compatibility to be more important. CV modifiers are a pain anyway, there are other scenarios that are not well supported, const pointers to const for one. This cannot be enforced at runtime anyway, the CLR has no support for it.

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

Sidebar

Related Questions

I'm using Visual Studio 2010 Ultimate SP1. I have around 225 unit tests in
i want to submit a form using Ext.Direct and iam following all the guidelines
I thought that latest Matlab does this automatically. I have tested the following exe
In our SQL Server 2005 database (tested using Management Studio with DBCC FREEPROCCACHE and
I'm using some CSS transitions like the following: .slide_left { -webkit-transition: all 0.25s ease-in;
The following code works fine under Cassini, but not at all under IIS. I
Problem The following scripts do exactly what I require, in all browsers tested except
Our test department has a series of web tests created using Visual Studio 2005
We have begun using the following branching structure in TFS 2010: All changes so
I'm using following htaccess rule which is proposed all over internet for removing index.php

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.