I want to return a handle to an object from a function. The receiver is not responsible for object lifetime management. Two straightforward ways I see of doing this are with a reference or a pointer. I rarely see references returned for this purpose... (maybe because you can't easily store references in containers?). What do you all prefer? A pointer 'feels' better to me, but then someone can call delete on the pointer.

@LucDanton Yeah, but I'm not out to protect against malicious intent. Most people don't delete references. Deleting pointers is common though. I can see people assuming ownership and calling delete nonchalantly

> Also C will let you do almost anything you want. For example. An array reference is a symmetric operation. So when you type arr[2] it doesn't actually matter whats in the bracket and what is in front of the bracket, therefore in C you can actually do 2[arr] to reference the array. Higher level languages won't let you do that.

> Now, this isn't unique to C++, lots of other languages have features that would allow you to be deceptive like this. However, C++ has a particularly bad culture of operator abuse, owing to its half-assed implementation of custom infix operators. It's pretty telling when the "Hello, World!" program, as it's typically written, contains a really blatant example of operator abuse.

@Cinch Its just a general consideration when building an API. I don't think there needs to be many details outside of "I want to return a handle that does not convey lifetime management". I think I'll stick with pointers

(I should note that this was an OOP class, not C++ specifically. The class mainly used Java with some C++ parallels. Which I’m fairly sure the teacher more or less had to have in the curriculum, and didn’t really care for.)

My intro programming course used C++... it was basically C with classes and no templates. The prof was pretty good though. My data structures prof just copied course slides and notes from other university sites and read them aloud in lecture

But no, really, I bet that you just can't ever delete a const int. In fact, if you return it, I'm sure that you're actually returning an actual math constant, which means that if you return an integrate(int) foo(), you'll get (const int)^2 * (1/2)

@ParkYoung-Bae Man... forget the void main() thing, the exam questions where they ask you to trace output were the WORST. Like, deliberately code golf tier stuff that you'd never see anyone write just for kicks... ugh