Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualRobot Ninja

Posted 15 December 2012 - 03:39 PM

Hey GameDev,

I'm in sort of a weird spot with my linked list class as part of a larger assignment. For my node class, my GetData function returns by reference. The template functions look like this:
// Node's GetData functions.
const T& GetData const { return m_data; }
T& GetData { return m_data; }
It seemed like a good idea for the Delete function in my linked list to return the node's data back to the user after deletion. However I'm not sure if it's even possible to return the data after, since my node's getter functions are returning by reference. Can you force a return-by-value from a return-by-reference function? Is there a better solution to this? Thanks.

#3Robot Ninja

Posted 15 December 2012 - 03:38 PM

Hey GameDev,

I'm in sort of a weird spot with my linked list class as part of a larger assignment. For my node class, my GetData function returns by reference. The template functions look like this:
// Node's GetData functions.
const T& GetData const { return m_data; }
T& GetData { return m_data; }
It seemed like a good idea for the Delete function in my linked list to return the node's data back to the user after deletion. However I'm not sure if it's even possible to return the data after, since my node's getter functions are returning by reference. Can you force a return-by-value from a return-by-reference function? Is there a better solution to this? Thanks.

#2Robot Ninja

Posted 15 December 2012 - 03:37 PM

Hey GameDev,

I'm in sort of a weird spot with my linked list class as part of a larger assignment. For my node class, my GetData function returns by reference. The template functions look like this:
// Node's GetData functions.
const T& GetData const { return m_data; }
T& GetData { return m_data; }
It seemed like a good idea for the Delete function in my linked list to return the node's data back to the user after deletion. However I'm not sure if it's even possible to return the data after, since my node's getter functions are returning by reference. Can you force a return-by-value from a return-by-reference function? Is there a better solution to this? Thanks.

#1Robot Ninja

Posted 15 December 2012 - 03:37 PM

Hey GameDev,

I'm in sort of a weird spot with my linked list class as part of a larger assignment. For my node class, my GetData function returns by reference. The template functions look like this:
// Node's GetData functions.
const T& GetData const { return m_data; }
T& GetData const { return m_data; }
It seemed like a good idea for the Delete function in my linked list to return the node's data back to the user after deletion. However I'm not sure if it's even possible to return the data after, since my node's getter functions are returning by reference. Can you force a return-by-value from a return-by-reference function? Is there a better solution to this? Thanks.

PARTNERS