Problem with local struct
jlh
jlh@gmx.ch
Sat Jan 22 01:17:00 GMT 2005
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 ------------------------ */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20050122/a9ae3c0b/attachment.sig>
More information about the Gcc-help
mailing list