M
mrstephengross
Hi folks... I've been sifting through archived postings on this, but
haven't quite found an answer yet. I've got a templated stand-alone
function:
template<typename T> void access(const T & t) { ; }
And a class 'Foo':
struct Foo {
friend void access(const Foo & f);
private:
int x;
};
As you can see, Foo is friended to the function 'access'. One more
thing to do: specialize access() for Foo:
template<> void access(const Foo & f) { f.x = 9; }
So access() should be able to work, right? Because access() has been
friended properly to Foo?
The following main() code, however, won't compile. The compiler
complains that 'x' is private:
int main() {
Foo f;
access(f);
}
Did I declare the friend function incorrectly? Or is this simply not
possible?
Thanks in advance,
--Steve ([email protected])
haven't quite found an answer yet. I've got a templated stand-alone
function:
template<typename T> void access(const T & t) { ; }
And a class 'Foo':
struct Foo {
friend void access(const Foo & f);
private:
int x;
};
As you can see, Foo is friended to the function 'access'. One more
thing to do: specialize access() for Foo:
template<> void access(const Foo & f) { f.x = 9; }
So access() should be able to work, right? Because access() has been
friended properly to Foo?
The following main() code, however, won't compile. The compiler
complains that 'x' is private:
int main() {
Foo f;
access(f);
}
Did I declare the friend function incorrectly? Or is this simply not
possible?
Thanks in advance,
--Steve ([email protected])