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

template/member function puzzle

P: n/a
Not sure if this a dumb syntax error, or if there some more subtle reason
why this doesn't work:

template <class ObjT> class Foo
{
typedef bool (ObjT::*TestFunction)();

public:
void Bar( ObjT* pObj,
TestFunction fn)
{
if (pObj->*fn()) // ERROR HERE : "term does not evaluate to a
function"
{

}
}
};

Any thoughts?

ta,
G.A.
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Glen Able" <Gl*******@gmail.com> wrote in message
news:cu*******************@news.demon.co.uk...
Not sure if this a dumb syntax error, or if there some more subtle reason
why this doesn't work:

template <class ObjT> class Foo
{
typedef bool (ObjT::*TestFunction)();

public:
void Bar( ObjT* pObj,
TestFunction fn)
{
if (pObj->*fn()) // ERROR HERE : "term does not evaluate to a
function"


This should "work":
if (pObj->fn())

or:
if ((*pObj->fn)())

Regards,
Sumit.
--
Sumit Rajan <su*********@gmail.com>
Jul 23 '05 #2

P: n/a

"Sumit Rajan" <su*********@gmail.com> wrote in message
news:37*************@individual.net...

"Glen Able" <Gl*******@gmail.com> wrote in message
news:cu*******************@news.demon.co.uk...
Not sure if this a dumb syntax error, or if there some more subtle reason why this doesn't work:

template <class ObjT> class Foo
{
typedef bool (ObjT::*TestFunction)();

public:
void Bar( ObjT* pObj,
TestFunction fn)
{
if (pObj->*fn()) // ERROR HERE : "term does not evaluate to a function"


This should "work":
if (pObj->fn())

or:
if ((*pObj->fn)())


No, those just give new errors: 'fn is not a member of class [whatever]' .
Jul 23 '05 #3

P: n/a

"Glen Able" <Gl*******@gmail.com> wrote in message
news:cu*******************@news.demon.co.uk...

"Sumit Rajan" <su*********@gmail.com> wrote in message
news:37*************@individual.net...

"Glen Able" <Gl*******@gmail.com> wrote in message
news:cu*******************@news.demon.co.uk...
Not sure if this a dumb syntax error, or if there some more subtle reason why this doesn't work:

template <class ObjT> class Foo
{
typedef bool (ObjT::*TestFunction)();

public:
void Bar( ObjT* pObj,
TestFunction fn)
{
if (pObj->*fn()) // ERROR HERE : "term does not evaluate
to
a function"


This should "work":
if (pObj->fn())

or:
if ((*pObj->fn)())


ahhhh...stupid precedence error, innit.

I should've done:

if ((pObj->*fn)())
{

}

cheers
G.A.
Jul 23 '05 #4

P: n/a

"Glen Able" <Gl*******@gmail.com> wrote in message
news:cu*******************@news.demon.co.uk...
ahhhh...stupid precedence error, innit.

I should've done:

if ((pObj->*fn)())
{

}


Nice work!
I made a complete mess of it!!

Regards,
Sumit.
--
Sumit Rajan <su*********@gmail.com>
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.