mem_fun_ref() and error C2352 in VC6 
Author Message
 mem_fun_ref() and error C2352 in VC6

class CHTMLTag        // is a base class
{
private:
    DWORD m_dwID;

public:
    CHTMLTag(DWORD dwID)
        {m_dwID = dwID;}
    virtual ~CHTMLTag() {}

    BOOL IsVisibleTag() const;

Quote:
}

typedef list<CHTMLTag*> HTMLTAGLIST;

HTMLTAGLIST listTags;

Given the above definitions (simplified for sake of discussion), I want to
find the last visible tag in listTags.  When I use

HTMLTAGLIST::reverse_iterator p = find_if(listTags.rbegin(),
plistTags.rend(), mem_fun_ref(&CHTMLTag::IsVisibleTag()));

The compiler complains:
D:\DEVELOP\OIT\POSTYERTLE\EXPORT\ml\converter.cpp(358) : error C2352:
'CHTMLTag::IsVisibleTag' : illegal call of non-static member function
        D:\DEVELOP\OIT\POSTYERTLE\EXPORT\ml\htmltag.h(129) : see declaration
of 'IsVisibleTag'

What gives?  Effective STL doesn't say anything about member functions
having to be static.



Sun, 11 Dec 2005 07:28:49 GMT  
 mem_fun_ref() and error C2352 in VC6
On Tue, 24 Jun 2003 18:28:49 -0500, "Bill Hammond"

Quote:

>class CHTMLTag        // is a base class
>{
>private:
>    DWORD m_dwID;

>public:
>    CHTMLTag(DWORD dwID)
>        {m_dwID = dwID;}
>    virtual ~CHTMLTag() {}

>    BOOL IsVisibleTag() const;
>}

>typedef list<CHTMLTag*> HTMLTAGLIST;

>HTMLTAGLIST listTags;

>Given the above definitions (simplified for sake of discussion), I want to
>find the last visible tag in listTags.  When I use

>HTMLTAGLIST::reverse_iterator p = find_if(listTags.rbegin(),
>plistTags.rend(), mem_fun_ref(&CHTMLTag::IsVisibleTag()));

On the above line you are trying to call IsVisibleTag as though it is
a static function, like this:
CHTMLTag::IsVisibleTag()
which is obvious illegal. I think you meant this:

HTMLTAGLIST::reverse_iterator p = find_if(listTags.rbegin(),
plistTags.rend(), mem_fun_ref(&CHTMLTag::IsVisibleTag));

Quote:
>The compiler complains:
>D:\DEVELOP\OIT\POSTYERTLE\EXPORT\ml\converter.cpp(358) : error C2352:
>'CHTMLTag::IsVisibleTag' : illegal call of non-static member function
>        D:\DEVELOP\OIT\POSTYERTLE\EXPORT\ml\htmltag.h(129) : see declaration
>of 'IsVisibleTag'

>What gives?  Effective STL doesn't say anything about member functions
>having to be static.

Note that you are unlikely to get any of this to work if you are using
VC6, since it has a prestandard <functional> header. You need VC.Net
(preferably 2003).

Tom



Sun, 11 Dec 2005 17:29:45 GMT  
 mem_fun_ref() and error C2352 in VC6

Quote:
> class CHTMLTag        // is a base class
> {
>     BOOL IsVisibleTag() const;
> }

> typedef list<CHTMLTag*> HTMLTAGLIST;

> HTMLTAGLIST listTags;

> Given the above definitions (simplified for sake of discussion), I
want to
> find the last visible tag in listTags.  When I use

> HTMLTAGLIST::reverse_iterator p = find_if(listTags.rbegin(),
> plistTags.rend(), mem_fun_ref(&CHTMLTag::IsVisibleTag()));

First, when taking an address of member function, you don't specify
parentheses at the end, like this: &CHTMLTag::IsVisibleTag . What you
have is calling IsVisibleTag() as if it were a static member, then
taking address of whatever it returns. No wonder the compiler is
confused.

Second, since you have a container of pointers and not of actual
objects, you need mem_fun rather than mem_fun_ref. Try

HTMLTAGLIST::reverse_iterator p = find_if(listTags.rbegin(),
    plistTags.rend(), mem_fun(&CHTMLTag::IsVisibleTag));

--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Sun, 11 Dec 2005 21:55:09 GMT  
 mem_fun_ref() and error C2352 in VC6
OK.  Now what if I want to use the following function:

BOOL CHTMLTag::IsTag(TagID eTagID)
{return (m_eTagID == eTagID);}

I'd like to do

HTMLTAGLIST::iterator p = find_if(listTags.begin(), plistTags.end(),
mem_fun1(&CHTMLTag::IsTag)(html_p));

but this won't compile ('()': function does not take 1 parameter).  Can I
use a member function with an argument as a predicate?


Quote:


> > class CHTMLTag        // is a base class
> > {
> >     BOOL IsVisibleTag() const;
> > }

> > typedef list<CHTMLTag*> HTMLTAGLIST;

> > HTMLTAGLIST listTags;

> > Given the above definitions (simplified for sake of discussion), I
> want to
> > find the last visible tag in listTags.  When I use

> > HTMLTAGLIST::reverse_iterator p = find_if(listTags.rbegin(),
> > plistTags.rend(), mem_fun_ref(&CHTMLTag::IsVisibleTag()));

> First, when taking an address of member function, you don't specify
> parentheses at the end, like this: &CHTMLTag::IsVisibleTag . What you
> have is calling IsVisibleTag() as if it were a static member, then
> taking address of whatever it returns. No wonder the compiler is
> confused.

> Second, since you have a container of pointers and not of actual
> objects, you need mem_fun rather than mem_fun_ref. Try

> HTMLTAGLIST::reverse_iterator p = find_if(listTags.rbegin(),
>     plistTags.rend(), mem_fun(&CHTMLTag::IsVisibleTag));

> --
> With best wishes,
>     Igor Tandetnik

> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken



Mon, 12 Dec 2005 02:10:40 GMT  
 mem_fun_ref() and error C2352 in VC6

Quote:
> OK.  Now what if I want to use the following function:

> BOOL CHTMLTag::IsTag(TagID eTagID)
> {return (m_eTagID == eTagID);}

> I'd like to do

> HTMLTAGLIST::iterator p = find_if(listTags.begin(), plistTags.end(),
> mem_fun1(&CHTMLTag::IsTag)(html_p));

> but this won't compile ('()': function does not take 1 parameter).
Can I
> use a member function with an argument as a predicate?

Try this:

HTMLTAGLIST::iterator p = find_if(listTags.begin(), plistTags.end(),
    bind2nd(mem_fun1(&CHTMLTag::IsTag), html_p);

You may also be interested in Boost's lambda and bind libraries

http://boost.org/libs/lambda/doc/index.html
http://boost.org/libs/bind/bind.html

--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken



Mon, 12 Dec 2005 02:21:53 GMT  
 mem_fun_ref() and error C2352 in VC6
Thanks.


Quote:


> > OK.  Now what if I want to use the following function:

> > BOOL CHTMLTag::IsTag(TagID eTagID)
> > {return (m_eTagID == eTagID);}

> > I'd like to do

> > HTMLTAGLIST::iterator p = find_if(listTags.begin(), plistTags.end(),
> > mem_fun1(&CHTMLTag::IsTag)(html_p));

> > but this won't compile ('()': function does not take 1 parameter).
> Can I
> > use a member function with an argument as a predicate?

> Try this:

> HTMLTAGLIST::iterator p = find_if(listTags.begin(), plistTags.end(),
>     bind2nd(mem_fun1(&CHTMLTag::IsTag), html_p);

> You may also be interested in Boost's lambda and bind libraries

> http://boost.org/libs/lambda/doc/index.html
> http://boost.org/libs/bind/bind.html

> --
> With best wishes,
>     Igor Tandetnik

> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken



Mon, 12 Dec 2005 03:56:28 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. mem_fun_ref problem (VC6)

2. Error C2352 - illegal call of non-static member function

3. C2352 Compiler error, (stupid newbie question)

4. Compiler Error C2352: illegal call of non-static member function

5. C2352 error with clear() method of list iterator

6. error C2784 when using mem_fun_ref with a member function that takes an parameter

7. VC6 fatal error C1001: INTERNAL COMPILER ERROR

8. mem_fun_ref

9. bind2nd and mem_fun_ref

10. Problem with 'mem_fun_ref'

11. mem_fun_ref

12. Bug in mem_fun_ref etc

 

 
Powered by phpBB® Forum Software