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

  • Home
  • SEARCH
  • 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 7025337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:57:40+00:00 2026-05-27T23:57:40+00:00

The example below illustrates a more complex but not dissimilar problem I’ve been trying

  • 0

The example below illustrates a more complex but not dissimilar problem I’ve been trying to solve elegantly. I have a set of templates which must be specialized and, in doing so, implement one or both of two interfaces: Readable and Writable, in each specialization. Specific implements both interfaces, and is then tested using main:

class Readable
{
protected:

    int values[3];

public:

    Readable()
    {
        // Does nothing.
    }

    int operator()(int i) const
    {
        return values[i];
    }
};

class Writable : public Readable
{
public:

    Writable()
    {
        // Does nothing.
    }

    using Readable::operator ();
    int& operator()(int i)
    {
        return values[i];
    }
};

class Specific : public Writable
{
};

void write_test(Specific& specific)
{
    // Error C2106: '=' : left operand must be l-value
    specific(0) = 1;
}

int main()
{
    Specific s;
    write_test(s);

    return 0;
}

The code above fails on VS 2008, 2010 with the following:

error C2106: ‘=’ : left operand must be l-value.

This strikes me as odd: have I overlooked something simple? I’ve compiled and run exactly this code using the [] operator, and all was well (as it should and always has been). It would appear to be some issue relating specifically to the behavior of this operator, an issue I am unfamiliar with.

  • 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-27T23:57:41+00:00Added an answer on May 27, 2026 at 11:57 pm

    This is a compiler error: the using declaration should work. To work around the problem just use delegation:

    class Writable: public Readable {
        ...
        int operator()(int i) const { return Readable::operator()(i); }
        ...
    };
    

    This implementation is longer than the implementation actually delegated to but it avoids problems if the version in Readable ever changes.

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

Sidebar

Related Questions

The example below may not be problematic as is, but it should be enough
I have created an example below to illustrate the problem I'm having. Basically, when
The example below throws an InvalidOperationException, Collection was modified; enumeration operation may not execute.
this example below works when hover event is trigered and when its not, its
In the example below I have a ListBox with dozens of font names in
How can I select the good method (I have in the example below show
Sorry for not included any example data for my problem. I couldn’t find a
The following diagram illustrates a problem I have encountered creating a Manhattan diagram: Overlapping
This example below illustrates how to prevent derived class from being copied. It's based
The 1st example below illustrates the working code. I want to take the working

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.