1

Our instructor has asked us to walk through a Template and explain what the various pieces of it are doing:

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

Here is what I've got so far:

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. 

If anyone could please correct/add to what I already have I would greatly appreciate it.

Ben Thomas
  • 13
  • 4
  • 1
    What you have pasted looks like an incorrect version of the definition of a templated class's member function. Please correct your code first. – Pradhan Aug 02 '14 at 03:26
  • If you make a chat room, I'll quite happily walk you through this. However such questions aren't really suitable for SO as it's quite broad and may be decided that it lacks basic understanding. – OMGtechy Aug 02 '14 at 03:27
  • 1
    `template set set::setDifference(const set &that) const;` - pretty sure that is what this was *supposed* to look like. – WhozCraig Aug 02 '14 at 03:32
  • @Pradhan it is almost correct except `:` should be `::` (and of course no capitalization), isn't it? – vsoftco Aug 02 '14 at 03:33
  • @OMGtechy Unfortunately I don't have over 20 reputation yet, so I am unable to create a chat room. Is there any other method of communication we could use? – Ben Thomas Aug 02 '14 at 03:36
  • @vsoftco You are right. And it doesn't look like it was edited after my post. For some reason, I thought the OP was asking about declaring a template class and wanted a clarification. – Pradhan Aug 02 '14 at 03:36
  • @BenThomas (comment deleted - skyping OP) – OMGtechy Aug 02 '14 at 03:44
  • Your code is wrong: `template` is correct, not `Template`. – ikh Aug 02 '14 at 03:53

1 Answers1

0

It's the beginning of the definition of the member function setDifference outside of its class body

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;
}
  • The return type is a newly created instance of the set class
  • The second set is indeed the class name; needed because setDifference lives in the namespace set<T>
  • you're right about the rest