开发者

Template classes c++ friend functions

My code has the same structure as the shown below. I have two container classes defined i开发者_JS百科n a single header file and each one of them has a friend function with parameters of type the other class so I get a compiling error which is something like 'Class2' - undeclared identifier.

Tried a few things but didn't work it out. I think that if add one more template parameter V to both of the templates and replace Class2<T> with it could be a solution but thing get much complicated if I use these containers in my program.I also thought to separate Class1 and Class2 into different headers and then include in Class1 Class2 and vice versa but I actually I doubt that this could work at all.

I really can't figure out how to solve this problem so please your help is much appreciated!

template<class T>
class Class1
{
  ...
  friend void function1(Class1<Class2<T>>&, const Class2<T>&);
  ...
};

template<class V>
class Class2
{
   ...
   friend void function2(Class1<V>);
   ...
};


Add a forward declaration for Class2 at the beginning of the file:

template<class V> class Class2;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜