[Cs3] Forward Class Template Declaration
Mikhail Nesterenko
mikhail at cs.kent.edu
Wed Mar 2 12:59:28 EST 2022
> From my understanding, forward declaring a templated friend function
> from a class protects the friend function from accessing data that it
> shouldn't. However, I do not understand how that actually works.Can you
> elaborate on that?
Look at this example:
http://antares.cs.kent.edu/~mikhail/classes/cs3/Examples/TemplateIntro/friendGeneralProblem.cpp
It has a general definition of a friend function "equal" (friend is a frient
of all instantiations) commented out.
This allows "malicous" implementation of "equal" that accesses private
members of unrelated global object ob2.b_
The commentted in specific definition of the friend function avoid
this problem and leads to compiler error.
Tbanks,
--
Mikhail
More information about the cs3
mailing list