0

In my set.h file - template(class T):

template<class T>
class set
{
 public:
  void add(const T& item);
 private:
}
#include "set.template"

In my set.template file:

template<class T>
void set<T>::add(const T& item)

In my main.cc file (where cset1 and cset2 are both set<char>):

cset1.unian(cset2);

The error:

error: no matching function for call to ‘set<char>::unian(set<char>&)’
note: candidates are: void set<T>::unian(const T&) [with T = char]

This happens throughout my program for all other functions (saying that its using set<char> or later in my program, set<Date> instead of T). Any ideas?

Edited by NV43: n/a

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by mike_2000_17
0

You seem to have defined the add() function but not a unian() function? If this is just a typo, please post code that should compile so we can see the whole structure.

0

If you need the "add" or "union" function to be adding or uniting two sets, then you need to make the function parameter a set:

template<class T>
class set
{
 public:
  void add(const set<T>& otherSet);
  void union(const set<T>& otherSet);
 private:
}
#include "set.template" //that's weird, btw.

And similarly in your set.template.

If you want your functions to work on individual components of type T, then make T the parameter type (well, const T&). But, then, you have to pass an element to the function, not a set.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.