Hey guys,

I have this code snippet:

template <typename ElementType, typename CompareClass>
struct Delegate {
	virtual bool geef(const ElementType &element){
		pair <set<ElementType, CompareClass>::iterator, bool> ret;  //this is line 196
		ret = elements.insert(element); //197
		return (ret.second); //198
	}
	
	virtual void output() = 0;
	
	set<ElementType, CompareClass> elements;
};

struct ArtiestenPrinter : public Delegate<Lied, LiedCompare> {
	virtual bool geef(const Lied &lied){
		bool nieuwElement = Delegate<Lied, LiedCompare>::geef(lied); // 210
		if (nieuwElement) {
			cout << lied.artiest;
		}
		return nieuwElement;
	}
	
	virtual void output(){
		for(set<Lied, LiedCompare>::iterator it = elements.begin();
			it != elements.end();
			it++){
			
			cout << it->artiest << endl;
		}
	}
};

Which gives me these errors:

196: error: type/value mismatch at argument 1 in template parameter list for 'template<class _T1, class _T2> struct std::pair'
196: error:   expected a type, got 'std::set<ElementType,CompareClass,std::allocator<_CharT> >::iterator'
196: error: invalid type in declaration before ';' token
198: error: request for member 'second' in 'ret', which is of non-class type 'int'
210:   instantiated from here
197: error: cannot convert 'std::pair<std::_Rb_tree_const_iterator<Lied>, bool>' to 'int' in assignment

I can't get my head around why the compiler is complaining, so any help is greatly appreciated.

Thanks in advance,

Here is the same problem in a small program, I still haven't figured it out why it thinks that set<ElementClass, CompareClass>::iterator is a value instead of a type.

#include <iostream>
#include <vector>
#include <set>
using namespace std;

class IntCompare {
	bool operator() (const int &a, const int &b){
		return (a == b);
	}
		
};

template <class ElementClass, class CompareClass>
class A {
public:
	virtual void foo(const int &x){
		pair< set<ElementClass, CompareClass>::iterator, bool> result;
	}
	
	set<ElementClass, CompareClass> elements;
};

/*class B : public A<int, IntCompare> {
public:
	virtual void foo(const int &x){
		cout << x*x << endl;
	}
};*/

int main (int argc, char * const argv[]) {
	A<int, IntCompare> mySet;
	for(int i = 0; i < 10; i++){
		mySet.foo(10);
	}
	
			
    return 0;
}

This code gives these compile errors:

main.cpp:17: error: type/value mismatch at argument 1 in template parameter list for 'template<class _T1, class _T2> struct std::pair'

main.cpp:17: error:   expected a type, got 'std::__debug::set<ElementClass,CompareClass,std::allocator<_CharT> >::iterator'

main.cpp:17: error: invalid type in declaration before ';' token
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.