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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:52:45+00:00 2026-06-04T14:52:45+00:00

I only ask this question because I have isolated it to pretty much three

  • 0

I only ask this question because I have isolated it to pretty much three lines of code, so it’s probably something really obvious that I just screwed up because I’m inexperienced:

Movie* ptr;
if(title == r->getItem().getTitle())
{
    ptr = &(r->getItem());
    cout << "Found: " << ptr->getTitle() << "!";
}

Essentially whats going on is that title == "The Godfather" so therefore that’s what
r->getItem().getTitle() is returning. What I don’t understand though, is that when I try to make a pointer that points to the Movie object returned by r.getItem(), I can’t use the pointer. It definitely had something assigned to it, but when I try to do ptr->getTitle() its returning null.

What on earth is going on?

  • 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-04T14:52:46+00:00Added an answer on June 4, 2026 at 2:52 pm

    I think you are doing something like this

    Movie& getItem () {
       Movie m ();
       return m;
    }
    
    /* ... */
    
    Movie * p = & (getItem ());
    

    The problem is that m is a stack object which gets lost after getItem has returned. That’s a common mistake in C++.

    The getTitle call should not work either, but it might by chance.

    You must create the object on the heap.

    My simple rule to avoid this: Don’t use the & operator altogether unless you haven’t thought about what you are doing ten times.

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

Sidebar

Related Questions

I have to ask this, because: The only thing I recognize is, that if
I ask this question here because I think this is more a regex question
A really simple question. For example, I have a class like this: .someclass {
I am hesitant to ask this question, because it appears as though many people
The question might be pretty vague I know. But the reason I ask this
Greetings, I would like to ask if creating Singleton to have only one active
I ask this because i'm using Partial classing to extend my db model, and
This question may have been asked already - but unfortunately, I could not find
I thought I would ask this question to see why many examples and people
This question probably looks a lot like IDE for ironpython on windows question here

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.