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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:32:56+00:00 2026-05-31T13:32:56+00:00

I wanted to do simple tests on my Word struct in Google Test. To

  • 0

I wanted to do simple tests on my Word struct in Google Test. To make the test code simpler and shorter I decided to write a comparison operator (even though I don’t really need one) and just use ASSERT_EQ, as per the primer. Even though everything seems OK, I get a compiler error:

/* Word.h */
namespace tgs {

struct Word {
    //something here
    Word();
    virtual ~Word();
    bool operator== (Word& rhs);
};
}

/* Word.cpp */
namespace tgs {
bool Word::operator== (Word& rhs){
  return true; //there are actual member comparisons here
}
}


/* TextAreaShould_test.cc */
TEST_F(TextAreaShould, DoSomething) {
  Word w1, w2;

  if(w1 == w2){ //compiles and runs ok
    0;
  }
  ASSERT_EQ(w1, w2); //produces following error
}

compiler error:

[ 86%] Building CXX object CMakeFiles/tests/TextAreaShould.test.dir/tests/TextAreaShould_test.cc.o
/usr/bin/c++    -I/home/nietaki/zpp/TheGameShow_build -I/home/nietaki/zpp/TheGameShow -I/home/nietaki/zpp/TheGameShow/google_mock/include -I/home/nietaki/zpp/TheGameShow/google_mock/gtest/include -I/usr/local/include   -o CMakeFiles/tests/TextAreaShould.test.dir/tests/TextAreaShould_test.cc.o -c /home/nietaki/zpp/TheGameShow/tests/TextAreaShould_test.cc
In file included from /home/nietaki/zpp/TheGameShow/tests/TextAreaShould_test.cc:8:
/home/nietaki/zpp/TheGameShow/google_mock/gtest/include/gtest/gtest.h: In function ‘testing::AssertionResult testing::internal::CmpHelperEQ(const char*, const char*, const T1&, const T2&) [with T1 = tgs::Word, T2 = tgs::Word]’:
/    home/nietaki/zpp/TheGameShow/google_mock/gtest/include/gtest/gtest.h:1363:   instantiated from ‘static testing::AssertionResult testing::internal::EqHelper<lhs_is_null_literal>::Compare(const char*, const char*, const T1&, const T2&) [with T1 = tgs::Word, T2 = tgs::Word, bool lhs_is_null_literal = false]’
/home/nietaki/zpp/TheGameShow/tests/TextAreaShould_test.cc:112:   instantiated from here
/home/nietaki/zpp/TheGameShow/google_mock/gtest/include/gtest/gtest.h:1326: error: no match for ‘operator==’ in ‘expected == actual’
/home/nietaki/zpp/TheGameShow/renderer/textarea/Word.h:25: note: candidates are: bool tgs::Word::operator==(tgs::Word&)

I also tried placing the comparison operator outside the class, not as a member, but it doesn’t seem to make much of a difference. I tried to do everything according to the Primer, but perhaps something is wrong.

  • 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-31T13:32:57+00:00Added an answer on May 31, 2026 at 1:32 pm

    The comparison operator doesn’t change any of the arguments so it can be const, as used by Gooogle Test:

    struct Word {
    
        Word();
        virtual ~Word();
        bool operator== (const Word& rhs) const;
    };
    

    …and everything works out allright.

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

Sidebar

Related Questions

I wanted to make some simple file recovery software, where I want to try
Want to write a typing test application (GUI, windows). Is simple terms. app shows
I wanted to use PHP Simple HTML DOM Parser to grab the Google Apps
I've made a simple app and I wanted to test pages for 404, 500
I have a simple function in jQuery and I wanted to test out the
I wanted to create a very simple method that switches between views in a
I wanted to set up a simple data communication between two C# applications, and
I wanted to create a page with a simple button which runs away from
I wanted know how the kernel is providing memory for simple C program .
I've developed a very simple host and client which I wanted to use to

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.