鉴于:
namespace foo{
class A {
public:
class B {
B();
int size();
const int last();
};
};
}
size 或 last 的函数定义的完整名称是:
int foo::A::B::size() {...}
const int foo::A::B::last() {...}
鉴于:
namespace foo{
template<typename T>
typename
class A {
public:
class B {
B();
B & operator ++();
int size();
const int last();
template< typename I, typename R>
R getsomethingfrom( const I & );
};
};
}
函数定义为:
template <typename T> int foo::A<T>::B::size() { ... }
template <typename T> const int foo::A<T>::B::last() { ... }
对于这些,获取指向成员函数的指针将是:
auto p = &foo::A<T>::B::size;
构造函数定义为:
template<typename T> foo::A<T>::B::B() {}
做以下事情之一:
foo::A<T>::B nb{}; // note, with nb() it complains
在模板中返回对 B 的引用的运算符函数定义很棘手:
template<typename T> // standard opening template....
typename foo::A<T>::B & // the return type...needs a typename
foo::A<T>::B::operator++() // the function declaration of operation ++
{ ... return *this; } // must return *this or equivalent B&
如果你很好奇,如果模板函数在 B 中,比如 getsomethingfrom,那么函数的定义是:
template< typename T> // class template
template< typename I, typename R> // function template
R foo::A<T>::B::getsomethingfrom( const I & ) // returns an R, takes I
{ R r{}; return r }