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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:27:10+00:00 2026-05-24T19:27:10+00:00

I have written a relational operator < as member of class Test bool Test::operator<(const

  • 0

I have written a relational operator < as member of class Test

bool Test::operator<(const Test& t) 
{
if (a<t)
      return true;
}

this code is in the header file, which I have included in my .cpp. However, when I compile my program, I get the following error:

test.h: 134:6: error: ‘a’ was not declared in this scope

Where do I declare ‘a’? should I write it in my header file as Test& a?
can you please help me fix this. thx!

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

    You’re supposed to be defining how a Test object may be compared to another object of type Test but in your code you do not define how, only that “a” – whatever that is, is less than the other object.

    class Test
    {
    public:
      Test(int myscore) { score = myscore; }
      bool operator<(const Test &t);
      int score;
    }
    
    bool Test::operator<(const Test &t) 
    {
      // Is less than if score is smaller
      if(score < t.score)
        return true;
      else
        return false;
    }
    

    Then in your program,

    // ...
    
    Test test1(4);
    Test test2(5);
    
    if(test1 < test2) std::cout << "4 is less than 5 by comparing objects\n";
    else std::cout << "Failed!\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen this in a lot of code written using Ruby-on-Rails. It seems
I have written the following code: @Entity @Table(name=person) @Inheritance(strategy=InheritanceType.JOINED) public class Person { private
I have written some code in my VB.NET application to send an HTML e-mail
I have written the following simple test in trying to learn Castle Windsor's Fluent
I have below code written with Eclipse ide: public interface X { final public
hey stackoverflowers. im having a few problems with the code i have written to
I have a ClearQuest API script written in Perl. If I do this: #print
I have a model with articles, events and people: class Person(models.Model): id = models.IntegerField(primary_key=True)
I have two Doctrine entities that have a one-to-many relationship, like this: License class
I have written this OSGI bundle: /* * To change this template, choose Tools

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.