- 浏览: 408941 次
- 性别:
- 来自: 上海
-
文章分类
- 全部博客 (309)
- xaml C# wpf (0)
- scala java inner clas (1)
- Tools UML Eclipse UML2 (1)
- Timer .NET Framework (1)
- perl (6)
- python function paramter (1)
- Python Docstring (1)
- Python how to compare types (1)
- Python (8)
- java (5)
- C# (76)
- C# WPF (0)
- p4 (0)
- WPF (46)
- .net (6)
- xaml (1)
- javascript (40)
- windows (10)
- scala (4)
- winform (1)
- c++ (48)
- tools (12)
- cmd (1)
- os (0)
- CI (0)
- shell (0)
- C (2)
- haskell (49)
- functional (1)
- tool (1)
- gnu (1)
- linux (1)
- kaskell (0)
- svn (0)
- wcf (3)
- android (1)
最新评论
There are three kinds of friends declaration that may appear within a class template.
A nontemplate friend class or friend function.
/** - A nontemplate friend class or friend function. * A nontemplate friend class or friend function. In the following example, the function foo(), the member function bar() * the member function bar() and the class foobar are friends to all instantiation of the class tepmlate QueueItem . * * this is a one-to-one relationship and the fiends are determined/fixed right in the declaration (there is only one declaration of the friends) */ class Foo { void bar(); }; class foobar {} template <class T> class QueueItem { friend class foobar; friend void foo(); friend void Foo::bar(); };
It is the one-to-one relationship, and there is only one function . and no matter how many instance of the function template , there is only one declaration.
A Bound friend class template or function template.
/** - A bound friend class template or function template * this is a one-to-one relationship and the friends are not determined (the friends is created when the class is instantiated).- */ template <class Type> class foobar { // }; template <class Type> void foo(QueueItem<Type>); template <class Type> class Queue { void bar(); }; template <class Type> class QueueItem { friend class foobar<Type>; friend class foo<Type>(QueueItem<Type>); friend class Queue<Type>::bar(); };
this is also a one-to-one relationship, but for a particular instantiation of the class template, there is one friend for that instantiation.
An unbound friend class
/** - An unbound friend class template or function template * unbound friend classes are multiple-to-one relationship * */ template <class Type> template QueueItem { friend class foobar; template <class T> friend void foo(QueueItem<T>); template <class T> friend void Queue<T>::bar(); };
There is a one-to-many relationship, where for a particular instantiation of the class template, there could be many function/classes that are the friends of the class template instantion.
发表评论
-
不安装Visual Studio,只用Windows SDK搭建VC环境
2013-12-31 21:52 15385首先你需要下载的是 Microsoft Windows S ... -
rpath - runtime search path
2013-04-03 11:36 1048RPath is a very interesting to ... -
C++ - autogenerated copy constructor and assignment operator gotchas
2013-01-24 13:32 802It has been changed that the s ... -
c++ - rethrow a exception gotchas
2012-12-23 10:57 1004As in my prevoius example in j ... -
c++ -typeid operator
2012-10-15 22:30 1092typeid is the one of the meager ... -
c++ - dynamic_cast revisit
2012-10-14 21:21 816There are several built-in type ... -
c++ - virtual inheritance example 1
2012-10-14 15:25 857we have discussed the virtual i ... -
c++ - virtual inheritance
2012-10-12 08:58 1035As we have discussed in the pos ... -
c++ type of inheritance
2012-09-28 08:58 781There are 3 types of inheritanc ... -
c++ - vritually virtual new
2012-09-27 23:59 986Let's see what if we want to cl ... -
c++ - virtual destructor
2012-09-27 22:01 1008As we all know that virtual des ... -
c++ - vritual function and default arguments
2012-09-27 08:56 1022As we all know that we virtual ... -
c++ - template specialization and partial specialization
2012-09-26 22:38 1371in this post, we are going to e ... -
c++ - member template in class template
2012-09-26 08:19 971class member template can be us ... -
c++ template class and the pattern to use its friends
2012-09-25 23:47 1009template class may defined thei ... -
c++ - class template default parameters
2012-09-25 08:18 886the template has parameter, it ... -
c++ - operator new and delete and an example of linked list stores by new/delete
2012-09-24 07:53 612The operator new and delete ope ... -
c++ - delete(void *, size_t) or delete(void *)
2012-09-24 07:18 1196In my previous dicuss, we have ... -
c++ - placement operator new() and the operator delete()
2012-09-23 15:22 902A class member operator new() c ... -
c++ - overloaded subscript operator - []
2012-09-23 08:50 1235You can overload the subscript ...
相关推荐
Header Files The #define Guard Header File Dependencies Inline Functions The -inl.h Files Function Parameter Ordering Names and Order of Includes Scoping Namespaces Nested Classes Nonmember, Static ...
- **Class Template Argument Deduction:** Use CTAD (Class Template Argument Deduction) to make template class instantiation more concise. - **Designated Initializers:** Use designated initializers for ...
(case=9976) 6946 VA Outline shows correct hierarchy for C++ classes containing friend methods without friend class declaration. (case=10740) 7072 .Net symbols are excluded from suggestion ...
- 在类设计时,考虑使用抽象基类(abstract base class)或模板类(template class)来提供更灵活的继承结构。 类嵌套是C++中的强大特性,但需要谨慎使用以防止产生难以调试的问题。理解并掌握超前引用的解决策略...
`typename`,`union`,`unsigned`,`using declaration`,`using directive`,`uuid`,`value class`,`value struct`,`virtual`,`void`,`volatile`,`while`,`asmautobad`,`_castbad`,`_...
assert`、`struct`、`switch`、`template`、`this`、`thread`、`throw`、`true`、`try`、`typedef`、`typeid`、`typedef`、`typename`、`union`、`unsigned`、`using declaration`、`using directive`、`uuid`、`...