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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:45:04+00:00 2026-05-25T13:45:04+00:00

I know that this might be a duplicate of: Return a "NULL" object if

  • 0

I know that this might be a duplicate of: Return a "NULL" object if search result not found

BUT, there’s something different going on with my code because the asterisk doesn’t solve my problem, which is this:

Normal Sphere::hit(Ray ray) {
   //stuff is done here
   if(something happens) {
       return NULL;
   }
   //other stuff
   return Normal(something, somethingElse);
}

But I get an error referencing the return NULL line: conversion from ‘int’ to non-scalar type ‘Normal’ requested

And another error and warning that referencing the last return line: warning: taking address of temporary and conversion from ‘Normal*’ to non-scalar type 'Normal' requested

I understand why I am getting this warning, but I don’t know how to fix it. How do I return a Normal object in the last line that persists after the function ends and how do I return a NULL object that first time? (If there’s a term for these types of returns, please let me know so I can also read up on it more.)

To clarify a commenter’s question, I’ve tried these things:

I tried doing this: Normal *Sphere::hit(Ray ray) in the cpp file and Normal *hit( Ray ray ); in the header file and I get this error: error: prototype for ‘Normal* Sphere::hit(Ray)’ does not match any in class 'Sphere'

I also tried this: Normal Sphere::*hit(Ray ray) in the cpp file and Normal *hit( Ray ray); in the header file and I get this error for the second return statement: cannot convert 'Normal*' to 'Normal Sphere::*' in return

Further clarification: I’m not asking about how pointers work. (That wasn’t the main question.) I’m wondering about syntax regarding pointers in C++. So, given the function I’ve specified above, I’ve gleaned that I should specify a return a pointer because C++ doesn’t have null objects. Got it. BUT, the problem then becomes: what should the function prototype look like? In the cpp file, I have what Bala suggested (which is what I had originally but changed it because of the following error):

Normal* Sphere::hit(Ray ray) {
   //stuff is done here
   if(something happens) {
       return NULL;
   }
   //other stuff
   return new Normal(something, somethingElse);
}

In the header file, I have Normal *hit(Ray ray), but I still get this message: prototype for 'Normal* Sphere::hit(Ray)' does not match any in class 'Sphere' At this point, it is unclear to me why it can’t find that function prototype. Here is the header file:

class Sphere
{
    public:
        Sphere();
        Vector3 center;
        float radius;
        Normal* hit(Ray ray);
};

Can anyone see why it’s complaining that there doesn’t exist a matching prototype for hit in the Sphere class? (I might move this to a separate question…)

  • 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-05-25T13:45:04+00:00Added an answer on May 25, 2026 at 1:45 pm

    I think you need something like

    Normal* Sphere::hit(Ray ray) {
       //stuff is done here
       if(something happens) {
           return NULL;
       }
       //other stuff
       return new Normal(something, somethingElse);
    }
    

    to be able to return NULL;

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

Sidebar

Related Questions

I know that this is somewhat subjective, but I wonder if there is a
Ok, you might say that this is a duplicate post but it is different.
I know that this is a simple question for PHP guys but I don't
I know that this is subjective and all, but still, can you provide some
I know that this has already been asked here but the answer (using a
I know that this feature will be deprecated in C++0x, but for me as
Okay, I know that 1) this is probably not possible with CSS alone and
This might be a duplicate question but as you can see they didn't get
This might be a duplicate question, however I did search and I got so
I know this might be more appropriate at Ask Different, but as I tried

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.