Hi, all -

I'm relatively new to iterators, and to template functions, so I suppose it was inevitable that the first time I tried to combine them, I'd run into a problem. Here's the function:

template <class T> int getVectort(ifstream & s,
								  long	nbrCells,
								  typename vector<T>::iterator iter)
	int		rc = 0;
	int32_t	temp;
	for (int i = 0; i < nbrCells; i++)
		s >> hex >> temp;
		*iter++ = temp;
	if (s.fail())
		rc = 1;
	return rc;

It builds OK, but when I attempt to call it, like this:

rc = getVectort<int32_t>(fileIn, DEMOD_NBR_INPUTS, iter);

I get this error message:

error: no matching function for call to 'getVectort(std::ifstream&, const long int&, __gnu_cxx::__normal_iterator<FlipFlopReg32*, std::vector<FlipFlopReg32, std::allocator<FlipFlopReg32> > >&)'

(I can post more code if desired; I'm just trying to keep the thread brief.)

Can someone please tell me what I'm doing wrong here? Thanks!

5 Years
Discussion Span
Last Post by mzimmers

Can you post more code? Specifically, how are DEMOD_NBR_INPUTS and iter defined? Here's an idea: write a complete program that's both small and exhibits the error. Then post that so other people don't have to play twenty questions with you just to get the necessary information for helping out.


* sigh *

Thanks, Narue...as I was constructing a small program, I discovered my error: I'd neglected to include the header file with the template function in it, in the file giving me the error.

I appreciate the assistance.


as I was constructing a small program, I discovered my error

That's what I was hoping would happen. Now you have one more tool in your troubleshooting arsenal.


I believe that at least one part of the problem can be fixed by changing the function prototype such that nbrCells is a const long reference rather than just a long :

template <class T> int getVectort(ifstream & s,
                                  const long & nbrCells,
                                  typename vector<T>::iterator iter)

This will allow for either a plain long argument or a const long argument; since DEMOD_NBR_INPUTS is, presumably, a const long , this will eliminate at least part of the problem, while also adding a check that nbrCells isn't being changed (which should be the case).


Good point, Schoil...I'll make that change as well. Thanks!

This article 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.