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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:19:18+00:00 2026-06-01T04:19:18+00:00

OK so I am working on some game logic, I have done a fair

  • 0

OK so I am working on some game logic, I have done a fair bit of research (as much as the internet will allow) and still don’t have a solid understanding of class and struct so please go gentle!

Basically, I want to be able to create an object with the properties all on one line ie.

object a{1, 1, 50, 15, 5}; // create object a 

and I want some extra stuff to be made up aswell like:

class object
{
public:
int x;
int y;
int h;
int w;
int s;
int x1;
int y1;
int ps;
int ns;
int x1 = x + w;
int y1 = y + h;
int ps = 0 + s;
int ns = 0 - s;
};
  • 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-06-01T04:19:19+00:00Added an answer on June 1, 2026 at 4:19 am

    I don’t know which language you’re working with, but it looks a bit like C++, so here’s an example:

    class Rect
    {
        public:
            int x, y;
            int w, h;
            int right, bottom;
    
            // This method is called a constructor.
            // It allows you to perform tasks on
            // the instantiation of an object.
            Rect(int x_, int y_, int w_, int h_)
            {
                // store geometry
                this->x = x_;
                this->y = y_;
                this->w = w_;
                this->h = h_;
    
                // calculate sides
                this->right = x_ + w_;
                this->bottom = y_ + h_;
            }
    };
    
    // You use the constructor in your main() function like so:
    Rect myObject(1, 1, 50, 15);
    
    // And you can access the members like so:
    myObject.x = 10;
    myObject.right = myObject.x + myObject.w;
    

    You cannot use operators inside the definition of a class as you proposed in your question. Operations on variables must take place inside a constructor (or other method).

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

Sidebar

Related Questions

I'm working on a simple board game in qt, and i have some problem
I'm working with some multithreaded code for a game project, and got a bit
I am working on a casual game with some improvement over time, much like
I have been working on a java simulation game for some time (remaking theme
I am working on a game and have an interesting question. I have some
I've been working with some game engines lately. They all have an Update() function
I'm working on a 3D space trading game with some people, and one of
I am currently working on a game in PHP and jQuery and at some
We're working on a multiplayer game, however we've run into some problems testing. I
I'm working on a online game. I got some problems with inserting new data

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.