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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:48:56+00:00 2026-06-01T22:48:56+00:00

I am working on a program but can’t understand working with pointers when classes

  • 0

I am working on a program but can’t understand working with pointers when classes are involved. I know I have to allocate memory for the pointer using new and am fine with this when not using classes. I can’t find a simple tutorial to explain how to do this particular task though. Could someone please give me some help? This is the relevant snippets what I have done so far but it is outputting random characters:

"Hangman.c"
{

class Hangman
{
public:
...
char* remainingLetters();
Hangman()
 {
  char* remaining=new char[26];
 }
~Hangman();

private:
char* remaining;
}

"Hangman.cpp"
{

...
 char* Hangman::remainingLetters()
{
 ...does task to find remaining letters;

 return remaining;
 }

  ostream& operator<< (ostream &out, Hangman &game)
  {
    out << "Letters remaining are: " << game.remaining <<endl

    return out;
  }
}

"main.cpp"
{
...
cout << game;
...
}
  • 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-01T22:48:57+00:00Added an answer on June 1, 2026 at 10:48 pm

    You’re not initializing you member. You should have:

    Hangman()
    {
       remaining=new char[26];
    }
    

    Your version:

     Hangman()
     {
        char* remaining=new char[26];
     }
    

    initializes a local variable called remaining, whose scope is the constructor.

    Also you should delete[] the memory in the destructor and implement the copy constructor and assignment operator.

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

Sidebar

Related Questions

Im working right now on a program that can divide, add, ect, but, im
I am working on kind of drawing program but I have a problem with
I don't understand why the first program in JSP is working, but the second
At work, I have started working on a program that can potentially generate hundreds
I have a C++ program which is working quite well using OpenMP to parallelize
I am working on a program with regexes, I have to filter them but
I'm trying to get my program working without boost usage, but can't find an
I have a working program on eclipse but my professor plans on running it
Hi i've got here a simple program, but it's not working properly. When i
I have a working program in C++ that generates data for a Mandelbrot Set.

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.