public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: f_ker@yahoo.co.uk
To: gcc-gnats@gcc.gnu.org
Subject: c++/7000: Compiler not picking up inherited function from base-class
Date: Tue, 11 Jun 2002 14:26:00 -0000	[thread overview]
Message-ID: <20020611212537.11835.qmail@sources.redhat.com> (raw)


>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:


             reply	other threads:[~2002-06-11 21:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-11 14:26 f_ker [this message]
2002-06-11 14:46 Gabriel Dos Reis
2002-06-11 14:56 F ker
2002-06-17  7:22 lerdsuwa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020611212537.11835.qmail@sources.redhat.com \
    --to=f_ker@yahoo.co.uk \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).