473,378 Members | 1,617 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

template/member function puzzle

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
4 1060

"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

"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

"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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Mikhail N. Kupchik | last post by:
Hi All. I have a question regarding Herb Sutter's idiom of implementation of operator= via nonthrowing swap() member function, to guarantee strict exception safety. The idea of the idiom is...
0
by: Chris F Clark | last post by:
In our C++ project we have some internal bug reporting macros that we use to get useful information when the program does something unexpected. Essentially at the point of the error, we invoke an...
7
by: Lionel B | last post by:
Greetings. The following code compiles ok and does what I'd expect it to do: ---------- START CODE ---------- // test.cpp
5
by: Levent | last post by:
Hi, Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1): #include <iostream> template<class T, unsigned N> struct Foo { void func(); }; template<class T, unsigned N>
2
by: pookiebearbottom | last post by:
Just trying to learn some things about templates. Was wondering how boost::tupple really works, but the headers were a bit confusing to me. I know you get do something like the following, just...
4
by: James Aguilar | last post by:
Guys, When I specialize a template class member function (I.e. a member function of a template class) based on that class' type, bad things happen. Here's some code: ---- test_header.h...
3
by: toton | last post by:
Hi, I want to specialize template member function of a template class . It is creating some syntax problem .... Can anyone say how to do it ? The class is something like this template<typename...
5
by: StephQ | last post by:
This is from a thread that I posted on another forum some days ago. I didn't get any response, so I'm proposing it in this ng in hope of better luck :) The standard explanation is that pointer...
2
by: Barry | last post by:
The following code compiles with VC8 but fails to compiles with Comeau online, I locate the standard here: An explicit specialization of any of the following:
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.