Friending Namespaces?

Don't really need to know this for any project, I just thought it would be really helpful later. My question: Can you friend a namespace like this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//header file

namespace testns{
	//I was thinking that if you could friend a namespace
	//you could allow instant higher privilege access
	//for people who want to make functions that access
	//private members without subclassing it
};

struct imastruct{
	private:
		friend testns;};

//file that includes above header

namespace testns{
	//here they would be able to define functions that can
	//access private members of imastruct
};
No. That would easily be abusable since someone can put whatever they want into that namespace and screw with your class.
I'm not really sure what the problem with that is... If they screwed with the class to that point that it was nonfunctional, they would only be hurting themselves because they are including and using it.

But whatever. What doesn't work doesn't work =P
The problem is that classes are supposed to let you prevent people from shooting themselves.
It would kind of violate the whole point of encapsulation if you allowed anyone to create functions themselves that modified private variables in your class.
Topic archived. No new replies allowed.