public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/7000: Compiler not picking up inherited function from base-class
@ 2002-06-17  7:22 lerdsuwa
  0 siblings, 0 replies; 4+ messages in thread
From: lerdsuwa @ 2002-06-17  7:22 UTC (permalink / raw)
  To: f_ker, gcc-bugs, gcc-prs, nobody

Synopsis: Compiler not picking up inherited function from base-class

State-Changed-From-To: open->closed
State-Changed-By: lerdsuwa
State-Changed-When: Mon Jun 17 07:16:29 2002
State-Changed-Why:
    Not a bug.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7000


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++/7000: Compiler not picking up inherited function from base-class
@ 2002-06-11 14:56 F ker
  0 siblings, 0 replies; 4+ messages in thread
From: F ker @ 2002-06-11 14:56 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/7000; it has been noted by GNATS.

From: =?iso-8859-1?q?F=20ker?= <f_ker@yahoo.co.uk>
To: Gabriel Dos Reis <gdr@codesourcery.com>
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/7000: Compiler not picking up inherited function from base-class
Date: Tue, 11 Jun 2002 22:47:36 +0100 (BST)

  --- Gabriel Dos Reis <gdr@codesourcery.com> wrote: >
 f_ker@yahoo.co.uk writes:
 > 
 > [...]
 > 
 > | I am trying to use a generic base class to supply an
 > operator()(T*) for all classes that have an operator()(T&) - but
 > the compiler doesn't seem to pick up the operator()(T*) from the
 > base class, and complains and rejects the code that   tried to call
 > it.
 > 
 > This is not a compiler misbehaviour, not a standard-conformant one.
 > The declarations of operator()(T&) are overriding the corresponding
 > pure virtual function in the base case _and_ *hiding* any other
 > overloads.  The moral is that you don't want to overload a pure
 > virtual function.
 > 
 > | Code:
 > | 
 > | #include <vector>
 > | #include <algorithm>
 > | 
 > | template<typename RefToPtrFObjConvertor_T_>
 > | class RefToPtrFObjConvertor
 > | {
 > | public:
 > |   virtual void
 > |   operator()(RefToPtrFObjConvertor_T_& arg) = 0;
 > | 
 > |   virtual void
 > |   operator()(RefToPtrFObjConvertor_T_* arg)
 > |   {
 > |     operator()(*arg);
 > |   }
 > | 
 > | };
 > | 
 > | struct Vertex
 > | {
 > |   bool is_transformed;
 > | 
 > |   class SetIsTransformedFlag
 > |     : public RefToPtrFObjConvertor<Vertex>
 > |   {
 > |   public:
 > |     bool value;
 > | 
 > |     SetIsTransformedFlag(bool arg)
 > |      : value(arg)
 > |     {
 > |     }
 > | 
 > |     void
 > |     operator()(Vertex& v)
 > 
 > This declaration hides
 > RefToPtrFObjConvertor<Vertex>::operator()(Vertex*).
 > Hence the error message (perhaps cryptic).  
 > 
 > -- Gaby 
 
 I asked 4 apparent 'experts' about this, none of them picked it up,
 which is very hard to believe.  Many thanks, and sorry for the
 misinformed post.
 
 
 
 __________________________________________________
 Do You Yahoo!?
 Everything you'll ever need on one web page
 from News and Sport to Email and Music Charts
 http://uk.my.yahoo.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c++/7000: Compiler not picking up inherited function from base-class
@ 2002-06-11 14:46 Gabriel Dos Reis
  0 siblings, 0 replies; 4+ messages in thread
From: Gabriel Dos Reis @ 2002-06-11 14:46 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/7000; it has been noted by GNATS.

From: Gabriel Dos Reis <gdr@codesourcery.com>
To: f_ker@yahoo.co.uk
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: c++/7000: Compiler not picking up inherited function from base-class
Date: 11 Jun 2002 23:39:37 +0200

 f_ker@yahoo.co.uk writes:
 
 [...]
 
 | I am trying to use a generic base class to supply an operator()(T*) for all classes that have an operator()(T&) - but the compiler doesn't seem to pick up the operator()(T*) from the base class, and complains and rejects the code that   tried to call it.
 
 This is not a compiler misbehaviour, not a standard-conformant one.
 The declarations of operator()(T&) are overriding the corresponding
 pure virtual function in the base case _and_ *hiding* any other
 overloads.  The moral is that you don't want to overload a pure
 virtual function.
 
 | Code:
 | 
 | #include <vector>
 | #include <algorithm>
 | 
 | template<typename RefToPtrFObjConvertor_T_>
 | class RefToPtrFObjConvertor
 | {
 | public:
 |   virtual void
 |   operator()(RefToPtrFObjConvertor_T_& arg) = 0;
 | 
 |   virtual void
 |   operator()(RefToPtrFObjConvertor_T_* arg)
 |   {
 |     operator()(*arg);
 |   }
 | 
 | };
 | 
 | struct Vertex
 | {
 |   bool is_transformed;
 | 
 |   class SetIsTransformedFlag
 |     : public RefToPtrFObjConvertor<Vertex>
 |   {
 |   public:
 |     bool value;
 | 
 |     SetIsTransformedFlag(bool arg)
 |      : value(arg)
 |     {
 |     }
 | 
 |     void
 |     operator()(Vertex& v)
 
 This declaration hides RefToPtrFObjConvertor<Vertex>::operator()(Vertex*).
 Hence the error message (perhaps cryptic).  
 
 -- Gaby


^ permalink raw reply	[flat|nested] 4+ messages in thread

* c++/7000: Compiler not picking up inherited function from base-class
@ 2002-06-11 14:26 f_ker
  0 siblings, 0 replies; 4+ messages in thread
From: f_ker @ 2002-06-11 14:26 UTC (permalink / raw)
  To: gcc-gnats


>Number:         7000
>Category:       c++
>Synopsis:       Compiler not picking up inherited function from base-class
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 11 14:26:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     f_ker@yahoo.co.uk
>Release:        3.1
>Organization:
>Environment:
GNU/Linux
gcc 3.1
i686

>Description:
I am trying to use a generic base class to supply an operator()(T*) for all classes that have an operator()(T&) - but the compiler doesn't seem to pick up the operator()(T*) from the base class, and complains and rejects the code that   tried to call it.

Code:

#include <vector>
#include <algorithm>

template<typename RefToPtrFObjConvertor_T_>
class RefToPtrFObjConvertor
{
public:
  virtual void
  operator()(RefToPtrFObjConvertor_T_& arg) = 0;

  virtual void
  operator()(RefToPtrFObjConvertor_T_* arg)
  {
    operator()(*arg);
  }

};

struct Vertex
{
  bool is_transformed;

  class SetIsTransformedFlag
    : public RefToPtrFObjConvertor<Vertex>
  {
  public:
    bool value;

    SetIsTransformedFlag(bool arg)
     : value(arg)
    {
    }

    void
    operator()(Vertex& v)
    {
      v.is_transformed = value;
    }

  };
};


class Polygon
{
public:
  std::vector<Vertex*> vertices;

  template<typename FObj_T_>
  class ForEachVertex
  {
  public:
    FObj_T_& fobj;

    ForEachVertex(FObj_T_& arg_fobj)
     : fobj(arg_fobj)
    {
    }

    void
    operator()(Polygon& polygon)
    {
      std::for_each(polygon.vertices.begin(),
		    polygon.vertices.end(),
		    fobj);
    }

  };

};

template<typename T>
Polygon::ForEachVertex<T>
do_for_each_vertex(T& arg)
{
  return Polygon::ForEachVertex<T>(arg);
}

std::vector<Polygon> polygons;

void
do_stuff1()
{
  std::for_each(polygons.begin(), polygons.end(),
		do_for_each_vertex(Vertex::SetIsTransformedFlag(false)));
}


void
do_stuff2()
{
  Vertex::SetIsTransformedFlag fobj(false);
  std::for_each(polygons.begin(), polygons.end(),
		do_for_each_vertex(fobj));
}



Full error message:

test_inherit_fcall_operator.cc: In function `void do_stuff1()':
test_inherit_fcall_operator.cc:91: could not convert `SetIsTransformedFlag(0)' 
   to `Vertex::SetIsTransformedFlag&'
test_inherit_fcall_operator.cc:81: in passing argument 1 of `
   Polygon::ForEachVertex<T> do_for_each_vertex(T&) [with T = 
   Vertex::SetIsTransformedFlag]'
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.1/include/g++/bits/stl_algo.h: In function    `_Function std::for_each(_InputIter, _InputIter, _Function) [with _InputIter    = __gnu_cxx::__normal_iterator<Vertex**, std::vector<Vertex*, 
   std::allocator<Vertex*> > >, _Function = Vertex::SetIsTransformedFlag]':
test_inherit_fcall_operator.cc:69:   instantiated from `void Polygon::ForEachVertex<FObj_T_>::operator()(Polygon&) [with FObj_T_ = Vertex::SetIsTransformedFlag]'
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.1/include/g++/bits/stl_algo.h:157:   instantiated from `_Function std::for_each(_InputIter, _InputIter, _Function) [with _InputIter = __gnu_cxx::__normal_iterator<Polygon*, std::vector<Polygon, std::allocator<Polygon> > >, _Function = Polygon::ForEachVertex<Vertex::SetIsTransformedFlag>]'
test_inherit_fcall_operator.cc:100:   instantiated from here
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.1/include/g++/bits/stl_algo.h:157: no 
   match for call to `(Vertex::SetIsTransformedFlag) (Vertex*&)'
test_inherit_fcall_operator.cc:42: candidates are: virtual void 
   Vertex::SetIsTransformedFlag::operator()(Vertex&)

>How-To-Repeat:
g++ -fsyntax-only file.cc
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-06-17 14:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-17  7:22 c++/7000: Compiler not picking up inherited function from base-class lerdsuwa
  -- strict thread matches above, loose matches on Subject: below --
2002-06-11 14:56 F ker
2002-06-11 14:46 Gabriel Dos Reis
2002-06-11 14:26 f_ker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).