Thread: How to return a pointer from a function in another file?

  1. #1
    Registered User
    Join Date
    Mar 2020
    Posts
    50

    How to return a pointer from a function in another file?

    I have a function that returns a pointer....I have labeled it with and without "static". In both cases when the function gets called again I lose the value of the pointer in the previous call, even when I declare a unique variable in main for the earlier calls...The function lives in another file other than main. Can someone tell me how to pass this pointer back to main such that the value of each call doesn't get updated overwriting the old return values?

    Thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,079
    You want to keep all the old return values? Then you need to store them in some kind of container in main, e.g., in an array.

    Look, why don't you post a highly simplified program with what you tried? Explain how does this simplified program fails to work the way you want, e.g., place comments indicating where a particular value was expected, but was not present.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. return pointer from function
    By skyr6546 in forum C Programming
    Replies: 5
    Last Post: 11-21-2019, 11:40 AM
  2. Return pointer to a vector of objects as a function return
    By Adaptron in forum C++ Programming
    Replies: 14
    Last Post: 04-07-2016, 09:23 AM
  3. Replies: 23
    Last Post: 11-23-2011, 12:29 PM
  4. Have function return file pointer
    By krogz in forum C Programming
    Replies: 6
    Last Post: 05-03-2007, 08:56 PM
  5. Can a function return a pointer to itself?
    By King Mir in forum C Programming
    Replies: 4
    Last Post: 04-19-2006, 01:15 PM

Tags for this Thread