By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,234 Members | 1,872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

tr1::bind in a template class

P: n/a
Hi all,

I have a template class

template<typename TC> class A{
public:
...
protected:
TC ObjTC;
}

where my possible TC classes should have a memberfunction double
operator()(double). Somewhere in a memberfunction of A I wish to use
tr1::bind in a call to a memberfunction MF like this

std::tr1::bind(&TC::operator(),ObjTC,_1) which maps to a tr1::function
in the argument list of MF.

but it won't compile: g++ 4.0.2 says that _1 is not defined... Has this
something to do with dependent names in a class? Should I have a
typename somwhere around TC::operator()? Please enlighten me...

thanks,
gert

PS a related question: the possible classes for TC should come from one
hierarchy with an abstract base class. Is there a way to force users of
my code to comply (and not have them using a class that happens to have
a similar interface)?

Dec 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Gert Van den Eynde wrote:
Hi all,

I have a template class

template<typename TC> class A{
public:
...
protected:
TC ObjTC;
}

where my possible TC classes should have a memberfunction double
operator()(double). Somewhere in a memberfunction of A I wish to use
tr1::bind in a call to a memberfunction MF like this

std::tr1::bind(&TC::operator(),ObjTC,_1) which maps to a tr1::function
in the argument list of MF.

but it won't compile: g++ 4.0.2 says that _1 is not defined... Has this
something to do with dependent names in a class? Should I have a
typename somwhere around TC::operator()? Please enlighten me...
a typename is evidently only necessary if you refer to a type dependend
onto a templated type. that should not be your problem here as you are
refering to a member function, not a type.

as boost::bind is the reference implementation for tr1::bind and up to
version 1.32 was unable to bind member operators your tr1
implementation may still have that limitation. you could try your code
with the latest boost library.

thanks,
gert

PS a related question: the possible classes for TC should come from one
hierarchy with an abstract base class. Is there a way to force users of
my code to comply (and not have them using a class that happens to have
a similar interface)?


see the tr1 extension header <type_traits> that features a
is_base_of<class Base, class Derived> template class with corresponding
traits to check for inheritance relations.

-- peter

Dec 12 '05 #2

P: n/a
Gert Van den Eynde wrote:

std::tr1::bind(&TC::operator(),ObjTC,_1) which maps to a tr1::function
in the argument list of MF.

but it won't compile: g++ 4.0.2 says that _1 is not defined


Implementation error or user error, can't tell. TR1 puts the
placeholders in namespace std::tr1::placeholders.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Dec 26 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.