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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:10:51+00:00 2026-06-03T14:10:51+00:00

Whenever I output a particular pointer address to std::cout , I get a crash:

  • 0

Whenever I output a particular pointer address to std::cout, I get a crash:

bool MyClass::foo() const
{
  std::cout << "this prints fine" << std::endl << std::flush;
  std::cout << d << std::endl << std::flush;  // crash!
  return true;
}

Where d is a pointer member of the class, i.e.:

class MyClass {
// ... 
 private:
  MyClassPrivate* d;
};

What could cause the application to crash? Even if it is a NULL pointer, or an initialized pointer, it should still print out the (perhaps invalid) address, right?

The application is compiled in debug mode, if that makes a difference. The function foo is not marked as inline.

Background: I am trying to track down a bug in an external application process. The bug is only caused when another application sends rapid-fire command to the process. I’m using std::cout to trace the execution of the external process.

  • 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-03T14:10:53+00:00Added an answer on June 3, 2026 at 2:10 pm

    If this is not a valid pointer, any access to a member field might cause an access violation. Non-virtual methods called on invalid pointers work just fine until they try to access a field, because the call itself doesn’t need to dereference this.

    For instance, this situation would crash roughly as you describe:

    MyClass* instance = nullptr; // or NULL if you're not using C++11
    instance->foo(); // will crash when `foo` tries to access `this->d`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whenever i try to run sqlmetal, i get this: 'sqlmetal' is not recognized as
whenever I try to call my ejb from a client, I get this error
Is there a way to get a console output whenever the App Engine Datastore
Whenever the following code runs i get extra output on the page which looks
whenever I run this below it gives the output but it also gives an
json url : http://www.nseindia.com/homepage/Indices1.json I am able to get the json output whenever i
ok this is very strange. My computers clock is correct, but whenever I output
Whenever the tags argument is not empty I get a NotSupportedException: Local sequence cannot
Is it possible to sandbox JavaScript output? What I mean is that whenever a
Whenever I run my program with fclose(outputFile); at the very end, I get an

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.