I was wondering if this is really C ++ if I return something from a method by reference, while the method is actually declared to return by value:
class A { public: int method(){ int i = 123; int& iref = i; return iref; } };
This compiles and seems to work. From what I understand, this should be returned by value, as stated in the method signature. I do not want to return a link to a local variable. Does anyone know if this is the "correct C ++ code" without traps?
source share