HELP - template error

hi all,
i get this error in my code: "error C2678: binary '-' : no operator found which takes a left-hand operand of type 'const CSet<CDate>' (or there is no acceptable conversion) 275".

a little description:
i have a CDate class which represent dates.
i have a CSet class (template) which represents all kind of groups (set theory).
i have a Menu class that controls the program.

the problematic code:

1
2
3
4
5
6
7
8
9
template <class T>
bool CSet<T>::operator > (const CSet<T> &other) const
{
	CSet<T> newGroup = (other - (*this));
	if (newGroup.sizeOfArray == 0) // if A - B = (empty set)    =>   A > B // 
		return true;
	else
		return false;
}



The - operator:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
template <class T>
const CSet<T> CSet<T>::operator - (const CSet<T> &other)
{
	CSet<T> newGroup;

	if (generalArray)
	{ // if this array is not empty //

		newGroup = *this;

		for (int i = ZERO; i < sizeOfArray; ++i)
		{ // check if value is not in both arrays //
			bool valueExists = false;

			for (int j = ZERO; j < other.sizeOfArray; ++j)
			{
				if ((*generalArray[i]) == (*other.generalArray[j]))
				{
					valueExists = true;
					break;
				}
			} // end of inner loop (j) //
			if (valueExists) // if value is not in both arrays - copy to the new object //
				newGroup -= (*generalArray[i]);
		} // end of external loop (i) //
	} // end of the condition - this array is not empty //

	return newGroup;
}


The Class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
template <class T>
class CSet
{
private:
	T **generalArray;
	int sizeOfArray;

public:
	CSet();
	CSet(const CSet<T> &obj);
	~CSet();

	int get_sizeOfArray() { return sizeOfArray; }

	CSet &operator = (const CSet<T> &objToCopy);
	CSet &operator += (const T &valueToAdd);
	CSet &operator -= (const T &valueToRemove);
	const CSet operator | (const CSet<T> &other); // OR //
	const CSet operator & (const CSet<T> &other); // AND //
	const CSet operator - (const CSet<T> &other); 
	bool operator == (const CSet<T> &other) const;
	bool operator != (const CSet<T> &other) const;
	bool operator > (const CSet<T> &other) const; // Contained //
	const CSet operator ^ (const CSet<T> &other); // XOR //
	friend ostream &operator << (ostream &out, const CSet<T> &groupToPrint)
	{
		out << "(";
		for (int i = ZERO; i < groupToPrint.sizeOfArray; ++i)
		{
			out << (*groupToPrint.generalArray[i]); 
			if (i != (groupToPrint.sizeOfArray - ONE))
				out << ", ";
		}
		out << ")" << endl;

		return out;
	}
};


please help
Last edited on
first of all your return statements have to be CSet<T> instead of CSet

no operator found which takes a left-hand operand of type 'const CSet<CDate>'
add a const to operator-
const CSet operator - (const CSet<T> &other) const;
hi there, thanks for the reply.

i have tried that. the error message has gone, but now i am experiencing another problem:
in the - operator - when i return return newGroup , it returns nothing.

what can i do now?

edit: it works just fine. i didnt see that i had another problem in other function.
thanks!
Last edited on
Topic archived. No new replies allowed.