So, I've got one template class, that I use twice for different objects. (e.g: template_class<A>, template_class<B>) This is fine and dandy. Now, I want to do an operation utilizing both of them, and their private data. One would think, hey, same base template class, there shouldn't be a problem if I make a member function in one and access both, right? Nope, treats them as distinct types so there is no way for one to access the private data of the other.
Now, how the hell do I friend the template class to other variants of itself? All I receive are parse errors, and consulting TC++PL is no damned help at all. If this is impossible I'm going to have to restructure the code to generically use void pointers, which isn't a big deal but is frustrating.
>>5
Three databases, each geared towards a specific type of data and bounding constraints based on the data type, but otherwise generic, queried against each other in an efficient manner. If efficiency wasn't as much of a concern, I'd go for a somewhat simpler implementation. And since encapsulation/self-contained data is one of the primary benefits of implementing classes like this... Blah.
Mostly it just annoys the shit out of me that this one fairly simple sounding thing is blocking me from an otherwise straightforward implementation.
Name:
Anonymous2006-08-18 17:59
>>3
You could probably do it with some template specialization, or something like that ;)
i.e. void Test<int>fail_it(Test<float> &t2) {
object = (truncate to int and fuck things up)t2.object;
}
Name:
Anonymous2006-08-18 19:57
Well, no thanks to you guys I figured it out, hehe. Inside the class definition:
template<class T2>
friend class Test<T>;
Believe it or not, that works. Apparently templating into the destination class and referencing the source is the way to friend other templates of the same base type. Its makes a sort of twisted amount of sense if you think about the secondary template statement deriving another template completely, even if it is backasswards from an implementation standpoint.
This gets filed into my "Nearly Useless Template Trivia" folder. This language inspires pure rage sometimes, I just have to keep telling myself "At least it's not Java."