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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:48:42+00:00 2026-05-14T18:48:42+00:00

I am currently working on a simple Scrabble implementation for a college project. I

  • 0

I am currently working on a simple Scrabble implementation for a college project.

I can’t get a part of it to work, though!

Check this out:

My board.h:

http://pastebin.com/J9t8VvvB

The subroutine where the error lies:

//Following snippet contained in board.cpp
//I believe the function is self-explanatory...
//Pos is a struct containing a char, y, a int, x and an orientation, o, which is not   //used in this particular case
void Board::showBoard()
{
    Pos temp;
    temp.o = 0;

    for (temp.y = 'A'; temp.y < (65 + TOTAL_COLUMNS); ++temp.y)
    {
        for (temp.x = 1; temp-x < (1 + TOTAL_ROWS); ++temp.x)
        {
            cout << _matrix[temp].getContents();
        }
        cout << endl;
    }
}

The errors returned on compile time:

http://pastebin.com/bZv7fggq

How come the error states that I am trying to compare two Pos when I am comparing chars and ints?

I also really can’t place these other errors…

Thanks for your time!

EDIT:

Since my whole project depends on Pos, I am going to try overloading the < operator for it… Can anyone give me a few tips on that? Keep in mind, I’m a beginner!

  • 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-14T18:48:42+00:00Added an answer on May 14, 2026 at 6:48 pm
    #define TOTAL_ROWS 15;
    #define TOTAL_COLUMNS 15;
    

    Theses are preprocessor definitions, which must not end in a semicolon. The semicolon will become part of the substitution text, so the compiler sees something like (65 + 15;) which is clearly wrong.

    In C++, it is better to use const variables instead of #defines. In this case, you could put the following in your Board.cpp:

    const unsigned int TOTAL_ROWS = 15;
    const unsigned int TOTAL_COLUMNS = 15;
    

    You can then make them available through your header by putting these in Board.h:

    extern const unsigned int TOTAL_ROWS;
    extern const unsigned int TOTAL_COLUMNS;
    

    Even cleaner is to declare them as class members. Put these in Board.cpp:

    const unsigned int Board::TOTAL_ROWS = 15;
    const unsigned int Board::TOTAL_COLUMNS = 15;
    

    And in Board.hpp, inside the public section of the class definition:

    static const unsigned int TOTAL_ROWS;
    static const unsigned int TOTAL_COLUMNS;
    

    They have to be static because they do not belong to any specific Board instance, but are rather properties of the class as a whole. You can then access them from outside the Board class by writing Board::TOTAL_ROWS etc.


    The other problem here is that you are creating a map<Pos, Cell>. The map template requires that its key type (Pos) has a valid < operator defined on it; internally, the map sorts its elements using this operator, so it can do fast lookups. The error occurs only at the point where you try to look something up in the map; this is due to the way templates work, so don’t break your head over it right now.

    One solution is to overload this operator yourself to define an ordering on Pos objects. I would not recommend that to a beginner, because

    • operator overloading is an advanced technique, and
    • you have to be very careful to define consistent behaviour, or else the map stars misbehaving, and
    • if you do this, you should also overload >, <=, and >=, == and !=.

    That being said, here is the code. This assumes that two Pos objects with the same x and y values are considered equal; it does not look at the value of o (which is a weird thing to have in a “coordinate” type anyway, and I don’t know what it’s used for).

    bool operator<(Pos const &l, Pos const &r) {
        if (l.y < r.y) return true;
        if (l.y > r.y) return false;
        if (l.x < r.x) return true;
        if (l.x > r.x) return false;
        return false;
    }
    

    The other (better) option is to abandon the Pos type completely, and represent your board as a two-dimensional array, or a vector of vectors. Its type would then be vector<vector<Cell> >. (Note the space between > >! Without it, this will be parsed as the right-shift operator >>!)

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

Sidebar

Related Questions

I'm currently working on a small project with OCaml; a simple mathematical expression simplifier.
I am currently working on a project and my goal is to locate text
I'm currently working on creating a new C# project that needs to interact with
I am currently working on a project with specific requirements. A brief overview of
I'm currently working on an internal sales application for the company I work for,
I currently working on an issue tracker for my company to help them keep
The system I am currently working on requires some role-based security, which is well
I'm currently working at a small web development company, we mostly do campaign sites
The company I'm currently working for is using Selenium for Uniting-Testing our User Interface.
We are currently working in a private beta and so are still in 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.