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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:38:05+00:00 2026-06-10T04:38:05+00:00

Until a test I’ve just made, I believed that only Constructors were not inherited

  • 0

Until a test I’ve just made, I believed that only Constructors were not inherited in C++. But apparently, the assignment operator= is not too…

  1. What is the reason of that ?
  2. Is there any workaround to inherit the assignment operator ?
  3. Is it also the case for operator+=, operator-=, … ?
  4. Are all other functions (apart from constructors/operator=) inherited ?

In fact, I encountered this problem as I was doing some CRTP :

template<class Crtp> class Base
{
    inline Crtp& operator=(const Base<Crtp>& rhs) {/*SOMETHING*/; return static_cast<Crtp&>(*this);}
};

class Derived1 : public Base<Derived1>
{
};

class Derived2 : public Base<Derived2>
{
};

Is there any solution to get that working ?

EDIT : OK, I have isolated the problem. Why the following isn’t working ? How to solve the problem ?

#include <iostream>
#include <type_traits>

// Base class
template<template<typename, unsigned int> class CRTP, typename T, unsigned int N> class Base
{
    // Cast to base
    public:
        inline Base<CRTP, T, N>& operator()()
        {
            return *this;
        }

    // Operator =
    public:
        template<typename T0, class = typename std::enable_if<std::is_convertible<T0, T>::value>::type>
        inline CRTP<T, N>& operator=(const T0& rhs)
        {
            for (unsigned int i = 0; i < N; ++i) {
                _data[i] = rhs;
            }
            return static_cast<CRTP<T, N>&>(*this);
        }

    // Data members
    protected:
        T _data[N];
};

// Derived class
template<typename T, unsigned int N> class Derived : public Base<Derived, T, N>
{
};

// Main
int main()
{
    Derived<double, 3> x;
    x() = 3; // <- This is OK
    x = 3;   // <- error: no match for 'operator=' in ' x=3 '
    return 0;
}
  • 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-06-10T04:38:07+00:00Added an answer on June 10, 2026 at 4:38 am

    The assignment operator is technically inherited; however, it is always hidden by an explicitly or implicitly defined assignment operator for the derived class (see comments below).

    (13.5.3 Assignment) An assignment operator shall be implemented by a
    non-static member function with exactly one parameter. Because a copy
    assignment operator operator= is implicitly declared for a a class if
    not declared by the user, a base class assignment operator is always
    hidden by the copy assignment operator of the derived class.

    You can implement a dummy assignment operator which simply forwards the call to the base class operator=, like this:

    // Derived class
    template<typename T, unsigned int N> class Derived : public Base<Derived, T, N>
    {
    public:
        template<typename T0, class = typename std::enable_if<std::is_convertible<T0, T>::value>::type>
        inline Derived& operator=(const T0& rhs)
        {
            return Base<Derived, T, N>::operator=(rhs);
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've never written a proper test until now, only small programs that I would
I'm running a test, and found that the file doesn't actually get written until
I was very happy with Moq until I needed to test a method that
We have a group of ~10 devs. who write internal test SW only. Until
I want to test my logic at Desktop (to eliminate pain of waiting until
The Problem: Until recently, I could build and test my app like normal. Now,
I am running a phread test program until it fails. Here is the main
I'm hoping maybe this is just an issue with the simulator but of course
I have created a Visual Studio 2008 sp1 test suite web test that uploads
I'm not even sure if this is possible but thought I'd ask anyway. Sorry

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.