This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem with local struct



I have troubles with a struct that is defined local to a function; see the code below. I compiled it as follows with gcc-3.4.3

$ g++ -c -Wall -pedantic -ansi -Wextra problem.cpp
problem.cpp: In function `void f()':
problem.cpp:22: error: no matching function for call to `bind2nd(f()::Func, int)'
********************************************************************************
However, if I move the entire "struct Func { ... }" block out of f() to global
scope, it compiles fine.  Therefore I assume there's nothing wrong with Func
itself, nor with the way it is being used in find_if().  I first thought that
maybe GCC doesn't fully support structs local to functions yet, but I guess
that's not the case, since I can properly instantiate and use Func, as shown
below.

Thanks,
jlh

/* ------------------------ snip ------------------------ */

#include <vector>
#include <functional>
#include <algorithm>

void f()
{
	struct Func : public std::binary_function<int, int, bool>
	{
		bool operator()(int, int) const
		{
			return true;
		}
	};

	/* works fine; can instantiate and use */
	Func f;
	f(0, 0);

	/* doesn't work: */
	std::vector<int> v;
	std::find_if(v.begin(), v.end(), std::bind2nd(Func(), 0));
}

/* ------------------------ snip ------------------------ */

Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]