1

I am looking at the node.js documentation for making a module. http://nodejs.org/api/addons.html

I understand template functions and template classes such as

template <class T>
void MyTemplateFunction(T a) 
{
    a.doSomething();
}

...

MyObj mo;
MyTemplateFunction <MyObj>(mo);

This code looks a little but like a template but I have never it before:

void init(Handle<Object> exports) {
    // what is <Object>?
}

Handle<Object> is a specification of a template class (as opposed to a template function, which you show above). There is a declaration of

template <class T>
class Handle {
    ...
};

somewhere in your code or in one of the header files that you included. Essentially, Handle<Object> is a class produced using a Handle template by replacing T with Object throughout the template's code.

4

3 回答 3

3

Presumably, Handle is a class template with a single type parameter:

template <typename T> class Handle;

and presumably Object is a type.

This instantiates the Handle class template, using Object as the template argument, to give a class; just as your example instantiates the MyTemplateFunction function template, using MyObj as the template argument, to give a function.

于 2013-05-15T16:44:32.120 回答
2

Handle<Object>模板类的规范(与上面显示的模板函数相反)。有一个声明

template <class T>
class Handle {
    ...
};

在您的代码或您包含的某个头文件中的某个位置。本质上,Handle<Object>是一个使用模板生成的类,通过Handle替换整个模板的代码。TObject

于 2013-05-15T16:42:36.253 回答
1

It's basically the same thing: exports is declared to be of type Handle<Object>, with Handle being a class template taking one (most likely) type argument. It's probably declared similar to the following:

template<typename T>
class Handle{...};
于 2013-05-15T16:44:16.060 回答