1

我们的讲师要求我们浏览一个模板并解释它的各个部分在做什么:

Template<class T> set<T> set<T>:: setDifference(const Set<T> &that) const

这是我到目前为止所得到的:

Template<class T>: declares the new template

set<T>: states the return type of our template

set<T>: pretty confused about the second set, possibly the class name?

setDifference: Calls on our setDifference function

const Set<T> &that: 
Parameters of setDifference, states set<T> cannot be modified within                          
setDifference or put on the left hand side of the equation. "&that" references "that"     
memory location to use/call

const (at the end): 
Our function can only be called by a const object of the class
nor can it call any non-const member functions or change member variables. 

如果有人可以请更正/添加到我已经拥有的内容,我将不胜感激。

4

1 回答 1

0

它是在其类体之外定义成员函数 setDifference 的开始

template <class T>
struct set{
//...
    set setDifference( const set& that) const;
};
template<class T>
set<T> set<T>::setDifference( const set<T>& that) const
{
    set<T> newInstance (...);
    //implementation of setDifference: newInstance = this - that
    return newInstance;
}
  • 返回类型是新创建的 set 类的实例
  • 第二组确实是类名;需要,因为 setDifference 存在于命名空间中set<T>
  • 你是对的
于 2014-08-02T11:00:47.493 回答