0

Is there any operator that can be overloaded so that an object can be made aware when a reference is assigned to it. For example:

Foo f;
Foo copy;
copy = f;        // Calls assignment operator
Foo *pF = &f;    // Calls operator& which can be overloaded
Foo copy2(f);    // Calls copy constructor explicitly
Foo & refF = f;  // Can f be made aware that this happened??

I realize that being able to do this is probably a recipe for some future disaster, but it seems potentially useful for tracing or debugging. (Trying to fend off the inevitable "what are you trying to achieve" responses. I'm not trying to solve any specific problem.)

1
  • You're trying to capture lhs.operator=(const T& rhs) as explicitly opposed to lhs.operator=(const T rhs)? Commented Nov 6, 2013 at 20:25

1 Answer 1

2

No, it can not. There is no using of any constructor to build the reference. Reference is simply an alias.

Sign up to request clarification or add additional context in comments.

1 Comment

I can't find anything either. As unsatisfying as this is, I guess it's a "solution".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.