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?

Recommended Answers

All 2 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.