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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:07:44+00:00 2026-06-14T15:07:44+00:00

I have a function defined like this: void doSomethingWithCustomer (const Customer &customer); One of

  • 0

I have a function defined like this:

void doSomethingWithCustomer (const Customer &customer);

One of my fellow developers called it like this:

Customer *customer = order.getCustomer();
doSomethingWithCustomer (*customer);

Unfortunately, the getCustomer method can return a nullptr, if the order is not tied to a customer.
If getCustomer returns a nullptr, then the application does not crash at the time of the call to doSomethingWithCustomer but rather within the function, where the customer reference is used.

Of course the correct way to write this is to check for customer not being a nullptr first, then call the function if we have a valid customer.
Normally we expect that if a function/method has a reference argument, that the caller checks the validity of it (which wasn’t the case here), instead of the function itself checking the argument.

I know that Visual Studio 2010 (and earlier versions) passes references by actually passing the pointer, but I wonder if this is indicated somewhere in the C++ standard. Can we assume that a reference is always passed as a pointer (personally, I wouldn’t rely on this, but it’s interesting to know it)?

Is it possible to tell Visual Studio that when passing a reference, it should automatically dereference it first and crash at the time of the call rather then somewhere much deeper (doing this in a debug version might be sufficient)?

  • 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-14T15:07:45+00:00Added an answer on June 14, 2026 at 3:07 pm

    Is it valid to assume that a reference is passed as a pointer?

    No, it is not.
    The standard does not mandate that the reference should be implemented in terms of pointer.

    How to actually implement a reference is an implementation detail which the standard leaves out for implementations to decide on. It only describes the expected behavior from an Reference and one of them is a reference can never be NULL in a standard conformant program.

    If your function parameter is expected to be NULL sometimes then you should pass it as an pointer.

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

Sidebar

Related Questions

I have a function which is defined like this: typedef void (*logprintf_t)(const char* format,
I have a function defined like this: public static void ShowAbout(Point location, bool stripSystemAssemblies
Suppose I have a function defined like this: class Foo() { public: void bar(MyClass*
In an ASP.MVC application, I have a function defined in my _ViewStart.cshtml like this:
I have Javascript function defined in the main index.html file. One part of this
i have a function defined as follows: void AddHeadCode(std::ofstream &ostream, size_t length){ ostream.write((char*)length, sizeof(length));
I have a function defined in a object like this: connect(callback?: (connected: bool) =>
I have one base class which holds a map for function pointers like this
I have a set of functions defined like this: public void foo1(int a, int
So I have this function: (define (try try-block catch-block finally-block) ; Implements try/catch/finally like

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.