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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:09:05+00:00 2026-05-28T02:09:05+00:00

I am trying to have a function return a boolean and an address in

  • 0

I am trying to have a function return a boolean and an address in memory.

I am loading a file from an archive and would like it to return A. if the file was found and B. a pointer to the file in memory after it is loaded. I realize that I cannot have two return types so I have the function as a boolean so it can tell me more importantly if the file exists in the archive. I figured I would do something like this:

// Hold the location of the file
char* location = NULL;

if(!archive.getFile(name, location))
{
    errorLog.writeError("Could not find the file!");
    return false;
}

If the file is not found, the function that calls the getFile will return false indicating the file was not found. That works great. But I am trying to figure out how to directly modify the pointer ‘location’ from within the getFile function.

Do I pass in the pointer? Or do I pass in the address of the pointer and modify it?

Here is the function in my header:

bool archive::getFile(string filename, char& location)

So to recap, I want to pass in the ‘location’ pointer, have it point to the file in the archive from getFile function and then when it returns, be able to use the ‘location’ pointer to access the file.

Thank you.

  • 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-28T02:09:05+00:00Added an answer on May 28, 2026 at 2:09 am

    Just return a pointer, and a null pointer if the thing is not found.

    char *getFile(std::string name) {
      return nullptr; // or just 0
    }
    

    Then you can do:

    if ((location = archive.getFile(name)) != 0) {
       // found
    }
    

    But that looks like C code.
    Alternatively:

    • return an empty std::string in the error case
    • return a bool, but pass a non-const reference to a string

    Or indeed pass a pointer-to-pointer or a reference-to-pointer, but that’s the least “idiomatic” C++ you could do IMO.

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

Sidebar

Related Questions

I'm trying to find out where this function comes from. Any one have any
I am trying to make this function download file from the internet. I pass
I have a function that takes a struct, and I'm trying to store its
I have a function with a chain of filters in jQuery. I am trying
I'm trying to get rid of floats in my functions. I have one function
At www.euroworker.no/order I have been trying to add a tooltip function but it seems
I am new to programming. I have been trying to write a function in
I have been messing around with Leaks trying to find which function is not
I have the following C++ function definition, which I am trying to call through
I'm trying to use the replace function in JavaScript and have a question. strNewDdlVolCannRegion

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.