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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:56:17+00:00 2026-06-10T23:56:17+00:00

I’m not sure really what to search for to try and find my answer,

  • 0

I’m not sure really what to search for to try and find my answer, so please redirect me to any relevant articles and I apologize in advance.

I’m really new to C++ and am trying to make a 3×3 CLI Tile game. I can assign the Tile objects to the private array of pointers in the TileGame constructor and see they have valid memory addresses (or so I think.) My problem is when I run a method to try and access that data. It looks like the the first element in the array has a value, but the others look very odd. I’m sure it’s something small, but I’m at a loss as to what I’m doing wrong. I’ve also tried creating an accessor method, but that only seemed to complicate things.

#include <iostream>
using namespace std;

class Tile
{
    private:
        int position;
        int tileID;
    public:
        Tile(int, int);
};

// tile constructor
Tile::Tile(int p, int id) : position(p), tileID(id) {}

class TileGame
{
    private:
        const int MAX_TILES;
        Tile* tiles[];
    public:
        TileGame();
        void shuffle();
};

// game constructor
TileGame::TileGame() : MAX_TILES(8)
{
    Tile* tiles[MAX_TILES];
    for (int i = 0; i < MAX_TILES; i++)
    {
        tiles[i] = new tile(i, i);
    }

    // spit out the addresses for each
    cout << endl << "From TileGame(): " << endl;
    for (int i = 0; i < MAX_TILES; i++)
    {
        cout << tiles[i] << endl;
    }
}

void TileGame::shuffle()
{
    // spit out the addresses for each
    cout << endl << "From TileGame(): " << endl;
    for (int i = 0; i < MAX_TILES; i++)
    {
        cout << tiles[i] << endl; // <-- This seems to be the problem
    }
}

int main()
{
    TileGame* game = new TileGame();
    game->shuffle();
}

This should compile (I had to retype it, so I hope I didn’t make mistakes.) The output that I get is something like:

From TileGame():
0x7f9349c03aa0
0x7f9349c03ab0
0x7f9349c03ac0
0x7f9349c03ad0
0x7f9349c03ae0
0x7f9349c03af0
0x7f9349c03b00
0x7f9349c03b10

From shuffle():
0x7fff9502752c
0x100
0
0
0
0
0
0

I arrived at this point when I kept getting seg faults by trying to access tiles[] values. Thoughts?

  • 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-10T23:56:18+00:00Added an answer on June 10, 2026 at 11:56 pm

    The tiles array that is created in the constructor of TileGame is not the tiles array in the Game object. Get rid of the one in the constructor.

    Also, too may pointers. The tiles array can hold Tile objects; no need for the indirection and the news. Similarly, there’s no need for game to be a pointer. Just create it as a TileGame object.

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

Sidebar

Related Questions

I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I need a function that will clean a strings' special characters. I do NOT
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.