messed up error with C++ class templates

Red Squirrel

No Lifer
May 24, 2003
71,329
14,090
126
www.anyf.ca
I'm making a class that uses templates which is basically a simple wrapper for vector but I'll be adding a few more features such as built in thread safety.

I get all these errors about "there are no arguments to..."
what did I do wrong?

Code:
../__header/rslib_i_containers.h: In member function ?bool rslib::xVector<T>::IsEmpty()?:
../__header/rslib_i_containers.h:71: error: there are no arguments to ?InternalUnlock? that depend on a template parameter, so a declaration of ?InternalUnlock? must be available
../__header/rslib_i_containers.h:71: error: (if you use ?-fpermissive?, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
../__header/rslib_i_containers.h: In member function ?long unsigned int rslib::xVector<T>::GetSize()?:
../__header/rslib_i_containers.h:79: error: there are no arguments to ?InternalUnlock? that depend on a template parameter, so a declaration of ?InternalUnlock? must be available
../__header/rslib_i_containers.h: In member function ?long unsigned int rslib::xVector<T>::GetMaxsize()?:
../__header/rslib_i_containers.h:87: error: there are no arguments to ?InternalUnlock? that depend on a template parameter, so a declaration of ?InternalUnlock? must be available
../__header/rslib_i_containers.h: At global scope:
../__header/rslib_i_containers.h:91: error: prototype for ?bool rslib::xVector<T>::Erase(T)? does not match any in class ?rslib::xVector<T>?
../__header/rslib_p_containers.h:36: error: candidate is: void rslib::xVector<T>::Erase(T)
../__header/rslib_i_containers.h:91: error: template definition of non-template ?bool rslib::xVector<T>::Erase(T)?
../__header/rslib_i_containers.h: In member function ?bool rslib::xVector<T>::Erase(T)?:
../__header/rslib_i_containers.h:98: error: expected primary-expression before ?==? token
../__header/rslib_i_containers.h:100: error: there are no arguments to ?InternalUnlock? that depend on a template parameter, so a declaration of ?InternalUnlock? must be available
../__header/rslib_i_containers.h: At global scope:
../__header/rslib_i_containers.h:105: error: prototype for ?bool rslib::xVector<T>::EraseAt(int)? does not match any in class ?rslib::xVector<T>?
../__header/rslib_p_containers.h:37: error: candidate is: void rslib::xVector<T>::EraseAt(int)
../__header/rslib_i_containers.h:105: error: template definition of non-template ?bool rslib::xVector<T>::EraseAt(int)?
../__header/rslib_i_containers.h: In member function ?bool rslib::xVector<T>::EraseAt(int)?:
../__header/rslib_i_containers.h:111: error: there are no arguments to ?InternalUnlock? that depend on a template parameter, so a declaration of ?InternalUnlock? must be available
../__header/rslib_i_containers.h: In member function ?T rslib::xVector<T>::PopFrom(int)?:
../__header/rslib_i_containers.h:121: error: there are no arguments to ?InternalUnlock? that depend on a template parameter, so a declaration of ?InternalUnlock? must be available
../__header/rslib_i_containers.h: In member function ?bool rslib::xVector<T>::Get(T&, int)?:
../__header/rslib_i_containers.h:132: error: there are no arguments to ?InternalUnlock? that depend on a template parameter, so a declaration of ?InternalUnlock? must be available
../__header/rslib_i_containers.h: In member function ?void rslib::xVector<T>::Add(T, int)?:
../__header/rslib_i_containers.h:143: error: there are no arguments to ?InternalUnlock? that depend on a template parameter, so a declaration of ?InternalUnlock? must be available
../__header/rslib_i_containers.h: In member function ?void rslib::xVector<T>::Clear()?:
../__header/rslib_i_containers.h:151: error: there are no arguments to ?InternalUnlock? that depend on a template parameter, so a declaration of ?InternalUnlock? must be available




rslib_p_containers.h:

Code:
/*
======================================================
rslib component: Containers prototypes
======================================================
*/


namespace rslib
{
	//extended vector class - features thread safety and extra functionability
	template <class T>
	class xVector

	{	
		private:
		#ifdef rslib_pthread
			MUTEX internalmutex;
			MUTEX externalmutex;
		#endif
		
		void InternalLock();
		void Internalunlock();
		
		public:
		vector<T> DATA; //we make this public in case we need to access it directly		
		
		xVector();
		~xVector();
		
		bool Lock(bool block); 	//lock for i/o  (multithreading)
		void Unlock();			//unlock for i/o(multithreading)
		bool IsEmpty();			//check if its empty
		
		unsigned long int GetSize();		//get current size
		unsigned long int GetMaxsize();		//get max system size
		
		void Erase(T);				//erase by element
		void EraseAt(int pos);		//erase by position
		T PopFrom(int pos);			//pop item from given position
		bool Get(T &give,int pos);	//get item by reference, returns false if index is invalid
		void Add(T item,int pos);	//add item 
		void Clear();				//clear array
	};




}



rslib_i_containers.h:

Code:
/*
======================================================
rslib component: Containers implimentors
======================================================
*/


namespace rslib
{
		template <class T>
		void xVector<T>::InternalLock()
		{
			#ifdef rslib_pthread
				while(MUTEX_LOCK(&internalmutex)!=0);
			#endif				
		}
		
		template <class T>
		void xVector<T>::Internalunlock()
		{
			#ifdef rslib_pthread
				MUTEX_UNLOCK(&internalmutex);
			#endif
		}
		
	
		template <class T>
		xVector<T>::xVector()
		{
			#ifdef rslib_pthread
				MUTEX_INIT(&internalmutex);
				MUTEX_INIT(&externalmutex);
			#endif
		}
		
		template <class T>
		xVector<T>::~xVector()
		{
			#ifdef rslib_pthread
				MUTEX_DESTROY(&internalmutex);
				MUTEX_DESTROY(&externalmutex);
			#endif
		}
		
		template <class T> 
		bool xVector<T>::Lock(bool block=true)
		{
			int ret=0;			
			#ifdef rslib_pthread	
				do
				{
					ret=MUTEX_LOCK(&externalmutex);
				}(ret!=0 && block);				
			#endif
			return (ret==0);
		}
		
		template <class T> 
		void xVector<T>::Unlock()
		{
			#ifdef rslib_pthread
				MUTEX_UNLOCK(&externalmutex);
			#endif
		}
		
		template <class T> 
		bool xVector<T>::IsEmpty()
		{
			InternalLock();
			return DATA.empty();
			InternalUnlock();
		}
		
		template <class T> 
		unsigned long int xVector<T>::GetSize()
		{
			InternalLock();
			return DATA.size();
			InternalUnlock();		
		}
		
		template <class T> 
		unsigned long int xVector<T>::GetMaxsize()
		{
			InternalLock();
			return DATA.max_size();
			InternalUnlock();		
		}
		
		template <class T> 
		bool xVector<T>::Erase(T)
		{
			bool ret=false;
			InternalLock();
			
			for(int i=0;i<GetSize();i++)
			{
				if(T==DATA[i])ret=EraseAt(i);
			}
			InternalUnlock();		
			return ret;
		}
		
		template <class T> 
		bool xVector<T>::EraseAt(int pos)
		{
			bool ret=true;
			InternalLock();
			if(pos>=0 && pos<DATA.size()) DATA.erase(DATA.begin()+pos);
			else ret=false;
			InternalUnlock();	
			return ret;			
		}
		
		
		template <class T> 
		T xVector<T>::PopFrom(int pos)
		{
			InternalLock();
			
			InternalUnlock();		
		}
		
		template <class T>
		bool xVector<T>::Get(T & give,int pos)
		{			
			InternalLock();
			bool ret=true;
			if(pos>0 && pos<DATA.size()) give=DATA[pos];
			else ret=false;
			
			InternalUnlock();		
			
			return ret;
		}
		
		template <class T>
		void xVector<T>::Add(T item,int pos=-1)
		{
			if(pos<0 || pos>DATA.size())pos=DATA.size();
			InternalLock();
			DATA.insert(pos,item);
			InternalUnlock();		
		}
		
		template <class T> 
		void xVector<T>::Clear()
		{
			InternalLock();
			DATA.clear();
			InternalUnlock();		
		}
}
 

Red Squirrel

No Lifer
May 24, 2003
71,329
14,090
126
www.anyf.ca
Turns out for calling member functions that are part of a template class I need to do:

this->InternalLock();

That fixed my errors. Have a few more obvious errors that I caught after but was harder to spot them throughout the 200+ other errors.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Your declaration of InternalUnlock() above doesn't capitalize the U, and it appears that some calls to it do capitalize the U:

private:
#ifdef rslib_pthread
MUTEX internalmutex;
MUTEX externalmutex;
#endif

void InternalLock();
void Internalunlock(); <----
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Also, two caveats to the above (I may be shooting into thin air here, since you didn't mention how xVector will be used):
1) internalmutex and externalmutex don't appear to be mutually exclusive.
2) If you're implementing the full vector api (e.g. things like swap), then you'll need some fairly smart locks to get it right. You'll want locks to scope with iterators, and I'm really not sure exactly how you should go about implementing the operator[] and at() functions.