This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/7000: Compiler not picking up inherited function from base-class


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]