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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:24:41+00:00 2026-05-28T07:24:41+00:00

If I try to compile: class Outer { class Inner { int t; };

  • 0

If I try to compile:

class Outer 
{
    class Inner 
    {
        int t;
    };
public:
    Inner inner_;
    bool operator ==(Outer rightSide);
};

bool Outer::operator ==(Outer rightSide)
{
    if (inner_ == rightSide.inner_)
        return true;
    return false;
}

I get an error:

/home/martin/Projects/Experimentation/Various-build-desktop/../Various/main.cpp:18: 
error: no match for ‘operator==’ in ‘((Outer*)this)->Outer::inner_ == 
rightSide.Outer::inner_’

Please, is it just me doing something wrong or is this a property of C++

EDIT:

Oh, I never realized that the operator == is never synthesized, I was so convinced that it is synthesized, that I did not bother to check.
Thank you Parapura Rajkumar!

  • 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-28T07:24:42+00:00Added an answer on May 28, 2026 at 7:24 am

    Comparison operators are never implicitly generated. Only these things are:

    • Default constructor,
    • Destructor,
    • Copy and move constructors,
    • Copy-assigment and move-assignment operators

    If you want to be able to compare your types, you’ll have to write your own comparison operators. If you implement them as members, then they should be declared const; otherwise, it will be impossible to compare constant objects. You might also consider taking arguments as constant references to avoid unnecessary copying; it makes little difference for simple types like these, but can be much more efficient for large or complicated classes. Something like:

    bool Outer::operator==(Outer const & rhs) const {
        return inner_.t == rhs.inner_.t;
    }
    

    or as a non-member function:

    bool operator==(Outer const & lhs, Outer const & rhs) {
        return lhs.inner_.t == rhs.inner_.t;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This compiles: class Ex1 { public int show() { try { int a=10/10; return
When I try to compile this: import java.awt.* ; class obj { public static
When ever I try to compile the following code I get the error: class
If I try to compile the following C++0x code, I get an error: template<int
Given the following code, I try to implement the public static Point operator +(int
Try to compile the following code in JDK7: import java.nio.file.*; public final class _DiamondSyntaxErrors
When I try to compile Gforth 0.7.0, I get the following error: $ ./configure
When I try to compile this: #include <map> #include <string> template <class T> class
When I try to compile to following code, I get two errors: Description Resource
I get the following error when I try to compile my C# program: The

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.