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

  • Home
  • SEARCH
  • 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 7409961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:09:38+00:00 2026-05-29T06:09:38+00:00

I am currenty doing a Sudoku game in c++. For that , I defined

  • 0

I am currenty doing a Sudoku game in c++. For that , I defined many classes including,
class Pos for position, and class Error for maintaining errors.

Now, in class Pos,

class Pos {
    int x;
    int y;
public:
    Pos();
    Pos(Pos const&);
    Pos(int,int);

    void    setPos(int,int);

    void    setx(int);
    void    sety(int);

    int    getx() const ;
    int    gety() const ;

    string getPosReport();

    virtual ~Pos();

}; 

What I have done:
I have restricted the value for x and y to lie between 0-9 by writing setx and sety as,

void Pos::setx(int x){
    if((x < 0) & (x > 9))
        throw  Exception("Invalid Position");
    else
        this->x = x;
}

void Pos::sety(int y){
    if((y < 0) & (y > 9)){
        throw Exception("Invalid Position");
    }
    else
        this->y = y;
}

My Problem: How Pos() must be defined.

What I have worked:

  1. Removing default constructor, didnt helped me because,

    class Error {
        string errmsg;    
        Pos pos1,pos2; // Pos() must be called!! default constructor cannot be removed!
        bool isError;
        // ...... 
    }
    
  2. I can initialize x and y to -1 in Pos() , but I feel that will bring instability in my code.

  3. I can have int* x and int* y in class Pos such that I can have x = y = NULL, but I feel Pointers will make my code relatively complex than now.

    so,it will be better if some one gives a solution which stimulates the scenario like x = y = N/A (not applicable)

  • 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-29T06:09:38+00:00Added an answer on May 29, 2026 at 6:09 am

    Give Error only constructors that initialise the Pos member objects. Then you won’t need to default-construct Pos anywhere.

    Initialising members is done with the “member initialisation list”, which you may find after the colon (:) below.

    class Error {
       Pos p;
    
       public:
         Error() : p(1,2) {};
    };
    

    This should be covered in your book.


    • Top credit for correctly identifying valid solutions, and the reasons not to adopt them.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently doing some work for a company that runs a legacy web
I'm currently doing some oracle sql analysis and often encounter valid sql statement that
I'm currently doing something like this; import java.util.*; public class TestHashMap { public static
I'm new to c++ and got a problem when doing homework (sudoku). Instruction said:
Im currently doing some android developer that lists items in a ListView , we
I am currently doing a project in C# that requires rendering MathML for the
So my goal is to write the method that solves a sudoku puzzle, we
I'm currently doing some extreme optimization on a JavaScript game engine I'm writing. And
I'm currently doing an aggregation query that groups all tracking id's and produces their
I am currently doing a programming assignment and it says that we should store

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.